I made this for a spectate script, but Button.Activated
doesn’t work and there are no errors. I have done nothing wrong, what is the issue?
FYI: I printed after the Button.Activated
connection was made and it printed, so it connects.
Script:
local Players = game:GetService("Players")
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local gui = script.Parent
local button = gui.Right
local label = gui.Player
local right = gui.Right
local left = gui.Left
label.Text = player.Name
local position = 0
local list = {}
local function update_camera(subject)
pcall(function()
camera.CameraSubject = subject.Value.Character.Humanoid
label.Text = subject.Name
end)
end
local function update_list()
list = game:GetService("Players"):GetPlayers()
end
update_list()
Players.PlayerAdded:Connect(update_list)
Players.PlayerRemoving:Connect(update_list)
position = table.find(list, player)
button.Activated:Connect(function()
label.Visible = not label.Visible
right.Visible = not right.Visible
left.Visible = not left.Visible
if not label.Visible then
update_camera(player)
end
end)
right.Activated:Connect(function()
position += 1
if position > #list then
position = 1
end
update_camera(list[position])
end)
left.Activated:Connect(function()
position -= 1
if position < #list then
position = #list
end
update_camera(list[position])
end)
Directory: