Added it to a localscript so I could use player = game.Players.LocalPlayer but now it wont work, the event won't fire :(
2 questions: 1.) How can I fix this script 2.) If I had this in a server script, how would I find the local player (eg. script.Parent.Parent.Parent.Parent, where is player/character located?)
gui = script.Parent players = game.Workspace.plyrs:GetChildren() print(script.Parent.Parent.Parent.Parent.Parent.Parent.Name) player = game.Players.LocalPlayer spectating = false
gui.MouseButton1Click:connect(function(mouse)
players = game.Workspace.plyrs:GetChildren()
if spectating == false and #players > 0 and not game.Workspace:FindFirstChild(player.Name) then
print("Attempting to spectate")
spectating = true
magic = math.random(1,#players)
Workspace.CurrentCamera.CameraSubject = game.Players:FindFirstChild(players[magic].Name).Character.Humanoid
mouse.KeyDown:connect(function(key)
players = game.Workspace.plyrs:GetChildren()
if key == "f" then
Workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
end
if spectating == true and #players > 0 and not game.Workspace:FindFirstChild(player.Name) then
if key == "e" then
if magic ~= #players then
magic = magic + 1
else
magic = 1
end
Workspace.CurrentCamera.CameraSubject = game.Players:FindFirstChild(players[magic].Name).Character.Humanoid
end
if key == "q" then
if magic ~= 1 then
magic = magic - 1
else
magic = #players
end
Workspace.CurrentCamera.CameraSubject = game.Players:FindFirstChild(players[magic].Name).Character.Humanoid
end
else
Workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
spectating = false
end
end)
else
Workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
spectating = false
end
end)

1 comment
The # in #players returns the number of (entries?) in a table. He did define the table in line 5. I do agree with you that spectating needs to be defined, though.