How do i make a infinite countdown loop

local seconds = 30
while wait(1) do
if seconds > 0 then
        seconds = seconds - 1
        script.Parent.Text = seconds
    elseif seconds <= 0 then
        seconds = 30
        script.Parent.Text = seconds
        game.ReplicatedStorage.RemoteEvent:FireServer(plr)
    end
end

This needs to be put at the very beginning of your script (that handles the rewards) in ServerScriptService.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)

P.S - Make sure you also put

end)

at the end of the script.

3 Likes

and what do you mean with
make sure
the player value is the same as the one in your LocalScript

game.ReplicatedStorage.RemoteEvent:FireServer(plr)

Notice how they both have the value plr?

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr)

The value should be the same. If you just copy and paste this code, you will be fine.

1 Like

and do i just put a remote event in ReplicatedStorage?

1 Like

alright_________________________________________<3

i think there is something wrong with my award handler

local seconds = 30
while wait(1) do
if seconds > 0 then
seconds = seconds - 1
script.Parent.Text = seconds
elseif seconds <= 0 then
seconds = 30
script.Parent.Text = seconds
game.ReplicatedStorage.RemoteEvent:FireServer(plr)
end
end

there is a error on plr its said unknown global “plr”

(This is starting to get off-topic so I urge you to create a new topic for further discussion on events. Your original issue with an infinite countdown loop seems to have been solved by a few previous posts.)

You should read over both of these developers hub articles because they explain events and the Roblox client and server model:

RemoteEvents and RemoteFunctions provide a communication between the client and the server. RemoteEvents provide a one way communication whereas RemoteFunctions provide a two way communication because you need to return a value. Here is a little example of how to you could use RemoteEvents:

(Hierarchy):

Image

(Server script in ServerScriptService):

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent

RemoteEvent.OnServerEvent:Connect(function(Player) -- Fires when the client fires the server. The first parameter automatically becomes the player.
	print(Player.Name.. ": Has fired the server")
	RemoteEvent:FireClient(Player) -- Fires the client
end)

(Client Scrip in StarterGui):

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent

RemoteEvent:FireServer() -- Fires the server

RemoteEvent.OnClientEvent:Connect(function() -- Fires when the server has fired the cliet
	print("Fired client")
end)

You don’t need to put the player in FireServer() because the first parameter automatically becomes the player when you use the OnServerEvent on the server.

The reason why you are getting this error is because you aren’t specifying the player. As I explained above you don’t need to put the player in FireServer() because the first parameter automatically becomes the player when you use the OnServerEvent.

The reason why you put the RemoteEvent in ReplicatedStorage is because it is a shared contained between the client and the server. This means both the client and server can access it.

1 Like

never mind i will make a simple one thx for help me a lot

thx for replying its ok ,i i really dont understand .so i wont use it