Why does line 5 of my script not give the player the Gui? I am willing to provide any information that wasn’t clear in this post.
game.Players.PlayerAdded:Connect(function(player)
game.ServerStorage.Spectate:Clone().Parent = player:WaitForChild(“PlayerGui”)
player:GetPropertyChangedSignal(“Team”):Connect(function()
if player.Team == game.Teams.Lobby then
game.ServerStorage.Spectate:Clone().Parent = player.PlayerGui
else
if player.PlayerGui:FindFirstChild(“Spectate”) then
player.PlayerGui.Spectate:Destroy()
end
end
end)
end)
No luck. I even simplified the script a little, but still no luck. It only gives the player the gui the first time, then never again.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if player.Team == game.Teams.Lobby then
game.ServerStorage.Spectate:Clone().Parent = player:WaitForChild(“PlayerGui”)
else
if player.PlayerGui:FindFirstChild(“Spectate”) then
player.PlayerGui.Spectate:Destroy()
end
end
end)
end)
Sometimes studio randomly doesn’t detect the PlayerAdded event (don’t ask me why, but I’ve experienced it randomly before). Maybe try testing it in-game and then checking the output?
You might not be receiving anything in the output if the conditional on Line 3 is returning false. Try adding a slight wait(.05) buffer under line 2 just to see if it affects anything.