dimanche 21 février 2021

Lua Tween Part Info

I am making a tween that uses data given from a Humanoid.Seated event, and I wanted to make the camera go to the end point when sat down, however, move back after they sat up. I have a feeling that the problem is with the part info, however I could be wrong.

This is the code:

The Sender/Event Handler:

local camPart = script.Parent
local camEvent = game.ReplicatedStorage.CamEvent
local blueSeat = script.Parent.Parent.BlueSeat.Seat --the correct seat person should be in

local bluePlayerName = script.Parent.Parent.Buttons.BlueEnter.PlayerName --the supposed name of person

bluePlayerName:GetPropertyChangedSignal("Value"):Connect(function ()
    if (bluePlayerName ~= "") then
        
        local char = game.Workspace:FindFirstChild(bluePlayerName.Value, true)
        local player = game.Players:GetPlayerFromCharacter(char)
        
        char.Humanoid.Seated:Connect(function (isSeated, seat)
            
            if (seat.Name == blueSeat.Name) then
            
                camEvent:FireClient(player, camPart, isSeated) --go to tween handler
            end
        end)
    end
end)

The Receiver/Tween Handler:

local TweenService = game:GetService("TweenService")
local cam = game.Workspace.Camera
local partData
local tween
local length = 2

local tweenData = TweenInfo.new(
    length,
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.Out,
    0,
    true,
    0
)

script.Parent.OnClientEvent:Connect(function (camPart, isSeated) --receiver
    
    partData = {
        CFrame = camPart.CFrame
    }
    
    tween = TweenService:Create(cam, tweenData, partData)
    
    if (isSeated == true) then
    
        cam.CameraType = Enum.CameraType.Scriptable --remove control
        tween:Play()
        
        wait(length / 2)
        tween:Pause() --stop at end point
        
    elseif (isSeated == false) then

        tween:Play() --go back/finish
        wait(length / 2)
        
        cam.CameraType = Enum.CameraType.Custom --give control back
    end
end)

Aucun commentaire:

Enregistrer un commentaire