Hello, first thanks for reading this. Basically what I am trying to do is make it so when a player joins or respawns a GUI is cloned to there head and that part work's. But the while() function does not it stops working on 19 where it says.
if v.Character.Head.TimeGui.Label.Time.Value >= Highest_Time then
I don't want a straight change this to this. But a push in the correct direction would be appreciated. Thanks for reading this.
local Highest_Time = 0
local Highest_Player_Name
game.Players.PlayerAdded:connect(function(Player)
repeat wait() until Player.Character
script:WaitForChild("TimeGui")
script.TimeGui:Clone().Parent = Player.Character.Head
end)
game.Workspace.ChildAdded:connect(function(Child)
repeat wait() until Child.Torso
script:WaitForChild("TimeGui")
script.TimeGui:Clone().Parent = Child.Head
end)
while wait(1) do
for i,v in pairs (game.Players:GetPlayers()) do
if v.Character.Head:FindFirstChild("TimeGui") then
if v.Character.Head.TimeGui.Label.Time.Value >= Highest_Time then
Highest_Time = v.Character.Head.TimeGui.Label.Time.Value
Highest_Player_Name = v.Name
print(v.Name)
print(Highest_Time)
end
end
end
if Highest_Player_Name ~= nil then
local Player = game.Players:FindFirstChild(Highest_Player_Name)
Player.Character.Head.TimeGui.Label.TextColor3 = Color3.new(255,0,0)
end
end

5 comments
Might it have anything to do with the potential problem of Character being nil for a Player? Is there an error message of any kind that could help to debug it?
Thanks, I got an idea of fixing it, if that is indeed the problem.
That didn't seem to work. I added a " while repeat wait() until v.Character" and I have the same problem.
How it the script behaving? Is the script erroring? If so what is the message?
That's the weird thing it is behaving fine. No errors, messages, warnings. And now I ran the code again after adding prints after each if and it runs through everyone of them no problem. That's why I don't see why it won't work.