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

How would I fix this timer script?

Asked by 10 years ago

Basically, I need to script to be a timer script that's the same for everyone, not local. I'm currently experiencing problems that whenever I reset/die, the time resets back to its full time. How would I make it so the time is the same for all the players, I tried creating an IntValue, but it's not working. Script below...

t=game.Workspace:FindFirstChild("Timer").Value
while true do
wait()
t=t+30
for i=1, 30 do
    t=t-1
    wait(1)
    for i, player in pairs(game.Players:GetPlayers()) do
    player.PlayerGui.TimerSet.Frame.Time.Text=tostring(t) 
end
end

t=t+45
for i=1, 45 do
    t=t-1
    wait(1)
    for i, player in pairs(game.Players:GetPlayers()) do
    player.PlayerGui.TimerSet.Frame.Time.Text=tostring(t)
end
end
for i, player in pairs(game.Players:GetPlayers()) do
player.Character.Humanoid.Health = 0
player.Character.Humanoid.MaxHealth = 0
end
end



Thanks!

0
Is this in a localscript? PiggyJingles 358 — 10y
0
No, It's not. nightmare13542 45 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

I just made a bit more simple. I don't like to rely on objects outside of scripts so I just put the variable inside of the script:

function newTimer(length)
    for i=length, 0, -1 do
        for j,p in pairs(game.Players:GetPlayers()) do
            if p.PlayerGui ~= nil then
                p.PlayerGui.TimerSet.Frame.Time.Text=i;
            end
        end
        wait(1);
    end
end

while true do
    newTimer(30);
    newTimer(45);
    for i,p in pairs(game.Players:GetPlayers()) do
        if p.Character.Humanoid ~= nil then
            p.Character.Humanoid.Health = 0;
        end
    end
end
0
It just says '1' then freezes nightmare13542 45 — 10y
0
Sorry, found the problem. Now it works. PiggyJingles 358 — 10y
0
It's local. -Resets when the player dies/each player has 'their own' timer. Different for everyone. I need a global one. nightmare13542 45 — 10y
0
Put it into a server-sided script and it works fine. PiggyJingles 358 — 10y
Ad

Answer this question