Script Error [CFrame]

I am looking to CFrame a camera pan intro that would loop but I can’t figure out why this code fails to even run 1 loop of it.

I came to post it because I cannot figure it out in HD or unofficial Roblox discord server.

Client;

game.ReplicatedStorage:WaitForChild("Cutscene1").OnClientEvent:Connect(function()
	print("client event started")
    local camera = game.Workspace.CurrentCamera
    camera.CameraType = Enum.CameraType.Scriptable
	wait(1)
    camera:Interpolate(game.Workspace.Part1.CFrame, game.Workspace.Part2.CFrame, 2)
    wait(2)
    camera:Interpolate(game.Workspace.Part2.CFrame, game.Workspace.Part3.CFrame, 2)
    wait(2)
    camera:Interpolate(game.Workspace.Part3.CFrame, game.Workspace.Part4.CFrame, 2)
    wait(2)
    camera:Interpolate(game.Workspace.Part4.CFrame, game.Workspace.Part5.CFrame, 2)
	wait(2)
    camera.CameraType = Enum.CameraType.Custom
end)```

Server;
game.Players.PlayerAdded:Connect(function(player)

game.ReplicatedStorage:FindFirstChild("Cutscene1"):FireClient(player)

end)```

Error:   06:08:01.463 - Attempted to use interpolation with a camera mode other than scriptable.
1 Like

The camera mode isn’t set to scriptable. Also, try not to use interpolate as it is more restricted than tweening.

Edit: I’m blind, you did set it to Scriptable. Try using tween and see if the same error occurs.

Developer hub says that Camera:Interpolate() function is deprecated, and that you should use TweenService instead. It also provides examples on how to use TweenService with Camera:

local TweenService = game:GetService("TweenService")
 
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
 
local tween = TweenService:Create(
	camera,
	TweenInfo.new(5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
	{
		CFrame = CFrame.new(0, 10, 100),
		Focus = CFrame.new(0, 0, 100)
	}
)
 
tween:Play()
2 Likes

How come it works with this function though? @Mokiros
https://gyazo.com/ab5e2673bc818b9269a731ae334082c1

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		game.ReplicatedStorage:FindFirstChild("Cutscene1"):FireClient(player)
	end
end)```

How come it works with this function though?

Deprecated does not mean nonfunctional.

You’re touching the part multiple times, which means the Cutscene1 fires multiple times, and thus the function in the local script runs multiple times. When the first function stops running, second one is still running, but the CameraType was already switched to Custom by the first function, which is why Interpolate produces an error.

Adding a debounce would fix this problem.

1 Like

You’re right, I wrongfully applied error from the topic to that post.

Adding wait(5) will fix it.

It may fix it in 95% of cases, but it is not the correct way of fixing the real problem.
@l7ura you don’t even need to fire the RemoteEvent on PlayerAdded. Instead you can just run the script when it loads instead of wrapping it in OnClientEvent.

And regarding to actual error: When the player loads, something sets CameraType back to Custom once after a certain amount of time. I haven’t found any default script that does that, so the only fix that I can suggest is adding camera.CameraType = Enum.CameraType.Scriptable before each Interpolate function:

local camera = workspace.CurrentCamera
wait(1)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part1.CFrame, workspace.Part2.CFrame, 2)
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part2.CFrame, workspace.Part3.CFrame, 2)
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part3.CFrame, workspace.Part4.CFrame, 2)
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part4.CFrame, workspace.Part5.CFrame, 2)
wait(2)
camera.CameraType = Enum.CameraType.Custom

Little nitpicks: use workspace instead of game.Workspace; making the chain of async function + wait is inefficient and you should make a function instead

2 Likes

Yup, that fixes it. Would you prefer repeat until or while true do to loop it?

@Mokiros Not sure how the way would be to do it,

repeat
	local camera = workspace.CurrentCamera
wait(1)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part1.CFrame, workspace.Part2.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part2.CFrame, workspace.Part3.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part3.CFrame, workspace.Part4.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part4.CFrame, workspace.Part5.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part5.CFrame, workspace.Part6.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part6.CFrame, workspace.Part7.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part7.CFrame, workspace.Part8.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part8.CFrame, workspace.Part9.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part9.CFrame, workspace.Part10.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part10.CFrame, workspace.Part11.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part11.CFrame, workspace.Part12.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part12.CFrame, workspace.Part13.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part13.CFrame, workspace.Part14.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part14.CFrame, workspace.Part15.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part15.CFrame, workspace.Part16.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part16.CFrame, workspace.Part17.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part17.CFrame, workspace.Part18.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part18.CFrame, workspace.Part19.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part19.CFrame, workspace.Part20.CFrame, 3.5) --d
wait(2)
camera.CameraType = Enum.CameraType.Scriptable
camera:Interpolate(workspace.Part20.CFrame, workspace.Part1.CFrame, 3.5) --d
until wait(2000000000)```

(yes the wait(2000000000) would not be correct way to do it)
1 Like