Search code examples
luaroblox

Why isn't CameraType changing into Scriptable, but prints the message verifying that the if statement is triggered?


I am trying to make an obby where the camera moves to a specified place with a part when the player steps on the checkpoint.

local cam = game.Workspace.CurrentCamera
local campart = game.Workspace.CameraPart
local checkpoint = script.Parent
local ever = false

checkpoint.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid and ever == false then
        cam.CameraType = Enum.CameraType.Scriptable
        cam.CFrame = campart.CFrame
        print("this is supposed to activate the cutscene now")
        ever = true
    end
end)

It doesn't display any errors, and when I step on the checkpoint, it prints the message inside the if statement, but does not change the CFrame of the camera. (The script is inside the checkpoint itself)

I tried to trigger the cutscene without the if statement, but still the camera type will not change to scriptable. I also tried to add a small delay, yet it still doesn't work.


Solution

  • CurrentCamera doesn't work in normal scripts but does in local scripts.

    This should work:

        local campart = game.Workspace.CameraPart
        local checkpoint = script.Parent
        local ever = false
        
        checkpoint.Touched:Connect(function(hit)
        if not hit.Parent:FindFirstChild("Humanoid") or ever = true then return end
            local humanoid = hit.Parent.Humanoid
            local cam = hit.Parent.Head.Camera
            cam.CameraType = Enum.CameraType.Scriptable
            cam.CFrame = campart.CFrame
            print("this is supposed to activate the cutscene now")
            ever = true
            end
        end)