Hello! I have made a simple camera system that shows my title screen at the start of the game using this code. It should be disabled when pressing the start button.
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local camera = workspace.Camera
local part = workspace.CameraPart
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Visible = false
script.Parent.Sound.TimePosition = 0
script.Parent.Sound.Playing = true
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = part.CFrame:Destroy()
end)
while true do
task.wait(1)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
end
Obviously using while true do repeats it every second. So I try to add a Player Added function instead so it only does it once like this:
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
local camera = workspace.Camera
local part = workspace.CameraPart
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Visible = false
script.Parent.Sound.TimePosition = 0
script.Parent.Sound.Playing = true
camera.CameraType = Enum.CameraType.Custom
end)
game.Players.PlayerAdded:Connect(function(plr)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
end)
And… Nothing. The camera doesn’t work and I don’t get a single error. Does anyone have any ideas as to why it is not triggering?
Wait…
You do not even need PlayerAdded. LocalScript fires everything for each individual player who joined the game. Just write this in the beginning without PlayerAdded: