Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do I make a king of the hill script?

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

Like have a hint show who was on the hill the longest. I've thought about this, and here was my idea. Two scripts, one in workspace and one in the brick.

--This is the one that goes in Workspace
game.Players.PlayerAdded:connect(function(plr)
    local time = Instance.new("NumberValue",plr)
    time.Value = 0
    time.Name = "time"
end)


h = Instance.new("Hint")
local longestTime = 0
while true do
    wait()
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.time.Value > longestTime then
            longestTime = v.time.Value
            h.Parent = workspace
            h.Text = v..": "..longestTime
        end
    end
end

I'm fairly certain I can handle the other script on my own. But is there a better way to do what I showed above? I don't usually like to use while loops because of the lag they tend to add. Any tips would be appreciated.

Answer this question