So I’m making a Flood Survival game and It’s managed by RemoteEvents.
But the problem Is, when the timer is to 0, the script should fire to the client. And to make sure It Isn’t broken, I’ve made a short code. And It Is broken!
Here’s the code for both scripts: (BOTH OF THE SCRIPTS ARE WIP!)
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CountdownEvent = ReplicatedStorage:WaitForChild("CountdownRemoteEvent")
local MainEvent = ReplicatedStorage:WaitForChild("MainEvent")
local Status = ReplicatedStorage:WaitForChild("Status")
local InRound = ReplicatedStorage:WaitForChild("InRound")
local Players = game:GetService("Players")
for t = Status.Value, 1, -1 do
CountdownEvent:FireAllClients(t)
Status.Value -= 1
wait(1)
end
while true do
if Status.Value == 0 then
print("Timer reached 0!")
InRound.Value = true
Players.PlayerAdded:Connect(function(player)
MainEvent:FireClient(player)
end)
break
end
wait()
end
Client Script
local ReplicatedStorage = game.ReplicatedStorage
local CountdownEvent = ReplicatedStorage:WaitForChild("CountdownRemoteEvent")
local MainEvent = ReplicatedStorage.MainEvent
local Status = ReplicatedStorage:WaitForChild("Status")
local InRound = ReplicatedStorage:WaitForChild("InRound")
local Players = game:GetService("Players")
MainEvent.OnClientEvent:Connect(function()
print("Remote fired!")
end)
You don’t need to fire every time the countdown changes. What you could do is have a StringValue inside ReplicatedStorage and have the countdown change there (like what you did)
-- Server
for t = Status.Value, 1, -1 do
Status.Value -= 1
wait(1)
end
then have the GUI on the client change the text every time it detects a change in value (changes made from the server will always replicate to the client).
-- Client
local Text = script.Parent.TextLabel
local Status = game.ReplicatedStorage:WaitForChild("Status")
Status.Changed:Connect(function()
Text.Text = Status.Value
end)
Now, through this, you don’t need to worry about if a new player will be able to see the active countdown, they will.
I think that’s not how you want to implement the code, since it keeps adding up new connections for every time Status.Value == 0.
Does this work instead?
-- Ridiculous janky method that works
while true do
for t = Status.Value, 1, -1 do
CountdownEvent:FireAllClients(t)
Status.Value -= 1
wait(1)
end
MainEvent:FireAllClients()
end
Im guessing your trying to fire the remote to all the players currently inside, if so maybe try this.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local CountdownEvent = ReplicatedStorage:WaitForChild("CountdownRemoteEvent")
local MainEvent = ReplicatedStorage:WaitForChild("MainEvent")
local Status = ReplicatedStorage:WaitForChild("Status")
local InRound = ReplicatedStorage:WaitForChild("InRound")
for t = Status.Value, 1, -1 do
CountdownEvent:FireAllClients(t)
Status.Value -= 1
wait(1)
end
InRound.Value = true
MainEvent:FireAllClients()