Round Based Start

Hi DevForumers!

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?

Thanks in advance!

1 Like

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
1 Like

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.

1 Like

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
1 Like

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 :joy:.

EDIT: Could I just put this code in a LocalScript in ReplicatedFirst and see if it works?

1 Like

I’m a little confused.

You can fire from server to server, use a BindableEvent and use the :Fire() method and the .Event event to listen for the fire.

1 Like

You’re kidding! That’s a thing?

Oof that means I been wasting my last year coding events the wrong way. Maybe I should review the API reference page.

1 Like

Nope, not kidding, that is a thing!

2 Likes