Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[ANSWERED] Why can't I move my Player in a Scriptable camera state?

Asked by 3 years ago
Edited 3 years ago

I wan't to know why I can't move my Player after a Camera Animation and after that a forced Camera State.

Here is my Code

local TweenService = game:GetService("TweenService")

local camera = game.Workspace.Camera

game.ReplicatedStorage.CameraEvent.OnClientEvent:Connect(function(part1, part2, speed)
    local tweenInfo = TweenInfo.new(
        speed,
        Enum.EasingStyle.Sine,
        Enum.EasingDirection.Out,
        0,
        false,
        0
    )

    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = part1.CFrame

    local tween = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
    tween:Play()

    wait(speed)

    camera.CFrame = part2.CFrame

end)

I hope somebody can help me

3 answers

Log in to vote
1
Answered by
Sparks 534 Moderation Voter
3 years ago

After you are done using the Scriptable CameraType, you have to reset the CameraType and CameraSubject. Also, you do not need to do "wait(speed)." Since you are waiting for the tween to finish, you can use tween.Completed:Wait() instead, which will pause the script until the tween is finished. You also do not need to not need to put camera.CFrame = part2.CFrame at the bottom, because once the tween is finished, that CFrame will have been reached.

local TweenService = game:GetService("TweenService")

local camera = game.Workspace.Camera

game.ReplicatedStorage.CameraEvent.OnClientEvent:Connect(function(part1, part2, speed)
    local tweenInfo = TweenInfo.new(
        speed,
        Enum.EasingStyle.Sine,
        Enum.EasingDirection.Out,
        0,
        false,
        0
    )

    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = part1.CFrame

    local tween = TweenService:Create(camera, tweenInfo, {CFrame = part2.CFrame})
    tween:Play()

    tween.Completed:Wait() --Wait for tween to finish

    --Set Camera back to player-default
    camera.CameraType = Enum.CameraType.Custom

    --Set Camera subject back to player
    camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid

end)
Ad
Log in to vote
0
Answered by 3 years ago

Solved because I haven't clicked into the Window

I'm stupid xD

0
breh FurryPapal 90 — 3y
0
0_0 Sparks 534 — 3y
Log in to vote
0
Answered by 3 years ago

Hmm, I'm not able to help you with the script you've made, but, however I have a script that does the same, it works with GUI Buttons, and I think actually any function, this is the script I use (Changed to work for you):

local TweenService = game:GetService("TweenService")
local Camera = game.Workspace.CurrentCamera

local function MoveCamera(StartPart, EndPart, Duration, EasingStyle, EasingDirection)
    Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = StartPart.CFrame
    local Cutscene = TweenService:Create(Camera, TweenInfo.new(Duration, EasingStyle, EasingDirection), {CFrame = EndPart.CFrame})
    Cutscene:Play()
    wait(Duration)
end

local function Cutscene()
    MoveCamera(game.Workspace.Part1, game.Workspace.Part2, 2.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

    wait(.5)
    Camera.CameraType = Enum.CameraType.Custom
    Camera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
end

script.Parent.MouseButton1Click:Connect(function()
    if enabled == true then return end Enabled = true
    Cutscene()
    Enable = false
end)

If you do not want this to be occur when a GUI button is clicked then remove code-lines 20-24.

Anyways, yes this does make your character move after the cutscene is over, you can even move when it's playing.

Answer this question