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

This camera script that should change the camera when you click a button but it won't work?

The camera change activates when the player clicks a GUI button.

Script:

local Camera = game.Workspace.CurrentCamera
local Players = game.Players.LocalPlayer
local button = game.StarterGui.Camera.TextButton

button.MouseButton1Click:Connect(function(player)
repeat wait() until Players.Character

Camera.CameraType = "Scriptable"
Camera.CFrame = workspace.Rocket.Rocket.CamPart.CFrame

end)

1 comment

0

You can't reference items in game.StarterGui, these are prototype instances that are copied into the local player's PlayerGui (child of the Player)

1 answer

✓ Accepted answer

You are attempting to reference StaterGui when you should be referencing the current gui which is PlayerGui.

Fix:

local Camera = game.Workspace.CurrentCamera
local Players = game.Players.LocalPlayer
local button = game.Players:FindFirstChild(Players.name).PlayerGui.Camera.TextButton

button.MouseButton1Click:Connect(function(player)
repeat wait() until Players.Character

Camera.CameraType = "Scriptable"
Camera.CFrame = workspace.Rocket.Rocket.CamPart.CFrame

end)

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