Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

It works in studio but not in roblox?

script.Parent.AwayC.MouseButton1Click:connect(function()
	game.Workspace.CurrentCamera.CameraSubject = game.Workspace.Cam1
	game.Workspace.CurrentCamera.CameraType = "Track"
end)

script.Parent.HomeC.MouseButton1Click:connect(function()
	game.Workspace.CurrentCamera.CameraSubject = game.Workspace.Cam2
	game.Workspace.CurrentCamera.CameraType = "Track"
end)

script.Parent.Person.MouseButton1Click:connect(function()
	game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
	game.Workspace.CurrentCamera.CameraType = "Custom"
end)

Top 2 functions work, its the bottom one thats troubling me

1 answer

✓ Accepted answer

Read over this blog post: https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online

It could very well be you're not waiting for the player''s character to load..

The line added on top of your code waits for the player's character to load before being indexed in any code below.

repeat wait() until game.Players.LocalPlayer.Character
script.Parent.AwayC.MouseButton1Click:connect(function()
    game.Workspace.CurrentCamera.CameraSubject = game.Workspace.Cam1
    game.Workspace.CurrentCamera.CameraType = "Track"
end)

script.Parent.HomeC.MouseButton1Click:connect(function()
    game.Workspace.CurrentCamera.CameraSubject = game.Workspace.Cam2
    game.Workspace.CurrentCamera.CameraType = "Track"
end)

script.Parent.Person.MouseButton1Click:connect(function()
    game.Workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.