Match won’t reset

So, I have been working on a time limit on my football game, but it won’t work. Here is the script:

local timeLeft = 90

while wait(1) do
    timeLeft -= 1
    if timeLeft <= 0 then 
    game.ReplicatedStorage.Remote:FireAllClients()
  end
end

game.ReplicatedStorage.Remote.OnClientEvent:Connect(function()
    game.ReplicatedStorage.RedGoals.Value = 0
    game.ReplicatedStorage.BlueGoals.Value = 0
    timeLeft.Value = 90
end)

The resetting of the values doesn’t work.

Any help greatly appreciated! :slight_smile:

Extra information: the calling doesn’t work because it used to be >=.

local timeLeft = 90

while wait(1) do
timeLeft -= 1
if timeLeft >= 0 then
game.ReplicatedStorage.Remote:FireAllClients()
end
end

game.ReplicatedStorage.Remote.OnClientEvent:Connect(function()
game.ReplicatedStorage.RedGoals.Value = 0
game.ReplicatedStorage.BlueGoals.Value = 0
timeLeft = 90
end)

this should fix it. since timeLeft isn’t a intValue you shouldn’t use timeLeft.Value but just timeLeft

1 Like

oh ok thanks a lot! This will really help if it works!

Oof… it doesn’t work…. @Di_Recc. It doesn’t under what or when to fire.

Well now i look at the code, is this inside a local script or a server script?

1 Like

Server script… is it correct or not? (All of it is inside it)

local timeLeft = 90

while wait(1) do
timeLeft -= 1
if timeLeft <= 0 then
game.ReplicatedStorage.RedGoals.Value = 0
game.ReplicatedStorage.BlueGoals.Value = 0
timeLeft = 90
end
end

if its inside a server script you cant wait on a clientevent.

1 Like

So where should it be? @Di_Recc?

The code i just send should be in the serverscript. This will reset the values, but itll immidiately start counting down again.

1 Like

Ok, so where should the others be? (Where would the local script go?)

Which local script? youre resetting the info for the server, the time is left and the scores for both teams. You dont need a local script. You might want to send a remote event to tell the local players that the ui needs to be reset.

Oh, ok! So I should not make a RemoteEvent, Gotcha!

tysm! You are a legend! @Di_Recc

1 Like

This would work, but you need to move:

game.ReplicatedStorage.Remote.OnClientEvent:Connect(function()
    game.ReplicatedStorage.RedGoals.Value = 0
    game.ReplicatedStorage.BlueGoals.Value = 0
    timeLeft.Value = 90
end)

To a local script, “OnClientEvent” is an event which listens for when either “FireClient” or “FireAllClients” is called from a server script.

Ok! Thanks for the extra info!