For whatever reason, the health of the player that was added to the spectate list doesn't update, nor will the button pressed attach the players camera.
-- Handled from the client
function getChar(Plr)
local char = game.Workspace:FindFirstChild(Plr.Name)
if char then return char end
end
function AttachCam(Plr)
local char = getChar(Plr)
game.Workspace.CurrentCamera.CameraSubject = char.Humanoid
end
game.Teams.Alive.PlayerAdded:Connect(function(player)
local List = script.Parent.GameUI.Back.SpecBack.ListBack.List
local Label = game.ReplicatedStorage.GuiStorage.Spec:Clone()
Label.Name = player.Name
Label.Lbl.Text = player.Name
Label.Lbl.Shadow.Text = player.Name
local char = getChar(player)
local bar = Label:WaitForChild("Bar")
bar.Size = UDim2.new(char.Humanoid.Health / char.Humanoid.MaxHealth, 0, 1, 0)
player.Character.Humanoid.HealthChanged:Connect(function()
bar.Size = UDim2.new(char.Humanoid.Health / char.Humanoid.MaxHealth, 0, 1, 0)
end)
Label.Parent = List
script.Parent.GameUI.Back.SpecBack.ListBack.List.CanvasSize = UDim2.new(1, 0, 0, 5 + (#List:GetChildren() * 35))
Label.MouseButton1Click:Connect(function()
AttachCam(game.Players:FindFirstChild(Label.Name))
script.Parent.GameUI.Back.ExitSpec.Visible = true
end)
end)
game.Teams.Alive.PlayerRemoved:Connect(function(player)
local fetchLabel = script.Parent.GameUI.Back.SpecBack.ListBack.List:FindFirstChild(player.Name)
if fetchLabel then
fetchLabel:Destroy()
end
end)
What the button looks like: https://gyazo.com/99ee14a6646fef4d8fddd05ffd00bdbe
