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

Game timer showing for all players?

Asked by 8 years ago

Hi, I've been having trouble with having my game timer show up on every player's screen. Can anyone help me with all the players seeing the same time? Here's my script that didn't work:

local timertag = Instance.new("NumberValue",workspace)
timertag.Value = 200
timertag.Name = "TimerTag"

function tag()
 timertag.Value = timertag.Value - 1
end

repeat wait() until game:WaitForChild("Players")
for _, player in pairs(game.Players:GetChildren()) do
    while timertag.Value > 0 do
        tag() player.PlayerGui.ScreenGui.TextLabel.Text = "Time left: "..timertag.Value
        wait(1)
    end
end

1 answer

Log in to vote
1
Answered by 8 years ago

Your issue is that you start looping through all players, but imidiately start the timer loop on first player.

Instead, you would want to start the timer loop and loop through every player for every second passed. It might sound slow, but it is really not.

local timertag = Instance.new("NumberValue",workspace)
timertag.Value = 200
timertag.Name = "TimerTag"

function tag()
 timertag.Value = timertag.Value - 1
end

repeat wait() until game:WaitForChild("Players")

while timertag.Value > 0 do
    -- Decrease time like you did
    tag() 

    -- Now apply this change to every player
    for _, player in pairs(game.Players:GetChildren()) do
        player.PlayerGui.ScreenGui.TextLabel.Text = "Time left: "..timertag.Value
    end

    -- Only then wait
    wait(1)
end

Edit: Sorry for accidentaly submit

0
Thank you so much <3 docrobloxman52 407 — 8y
Ad

Answer this question