I am making a round-based game and for some reason I can’t think of a way to start it. The first round starts when there are >2 ppl, and when this is true, it fires a remoteevent called “StartRound” which would take care of the rest of the process. How would I go about making this work?
I recommend handing everything on the server to prevent exploits. You can use RemoteEvents to send data to the client though, such as timers, winners etc…
game.Players.PlayerAdded:Connect(function()
if #game.Players:GetPlayers() > 2 then
BindableEvent:Fire()
end
end
The winning script would fire the event after the round is done.
Wouldn’t that bit of code fire the event whenever there are >2 players in the server, even if it has been fired before? This would mean every join would fire it.
Yeah, you’d have to add a debounce. Something like this should work:
local gameHasStarted = false
game.Players.PlayerAdded:Connect(function()
if #game.Players:GetPlayers() > 2 and gameHasStarted == false then
gameHasStarted = true
BindableEvent:Fire()
end
end
Well, this code is a server script, and if I fire the event from a server script it can only fire clients… would I just select a random player to fire the server when they receive the client event? This is a really bad way to handle it I guess but it might work .
EDIT: Could I just put this code in a LocalScript in ReplicatedFirst and see if it works?