So I have a crown that is supposed to be given to the player who has the highest “Time” stat in the game. How would I do that? This is my current script. It does it for the first time when a player dies. After the player is dead, it doesn’t work again. Any feedback will be appreciated.
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(character)
while wait(1)do
local function getMax(stat)
local player = nil
local value = -math.huge
local temp
for _, p in ipairs(game.Players:GetPlayers()) do
temp = p.leaderstats.Time.Value
if (temp > value) then
player = p
value = temp
end
end
return player
end
local richestPlayer = getMax("Time")
if (richestPlayer)
then
local clone = script.Parent.Parent:Clone()
clone.Handle.Anchored = false
clone.Parent = character
end
end
end)
end)