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.
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):
(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.