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

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

Asked by 4 years ago

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)

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) EmilyBendsSpace 1025 — 4y

1 answer

Log in to vote
0
Answered by
Robowon1 323 Moderation Voter
4 years ago

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)

Ad

Answer this question