Trying to find a way to detect if player is in a mini game or not

  1. What do you want to achieve?

I want to achieve a (mabye) simple system has the ability to detect if player is in the playing region or lobby region. If the value of players in the playing region is 0 during a game, restart the mini game.

  1. I’ve tried detecting if the player is touching the in-game zone, then if they are they would add a value to the playing value, and if in the lobby zone, subtract 1 from the playing value. But if the player stops moving in the in-game zone, they are not detected with touchservice, so this is definitely a liable “solution.”
    I’ve also tried region 3, which I think would work, but I need help on it because

So, checking if players are in-game or not would like like this if statement:

if playing.Value == 0 then
    game.ReplicatedStorage.eventsFolder.EveryoneDied:FireAllClients()
    print 'all players died'
end

or it could look like this (doesn’t have to be value but could be a number in script)

if playing == 0 then
    game.ReplicatedStorage.eventsFolder.EveryoneDied:FireAllClients()
    print 'all players died'
end
--these are server scripts (if statments above)--
  1. What solutions have you attempted?

TLDR, Many.

First, I tried using region3: I used both vector 3’s to create a region; doesn’t work…I don’t have any reason.

Secondly, I tried checking if touched would be a good idea, but if you don’t move in a can-collide false zone, it doesn’t consistently detect you’re actually IN the zone.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

This is an diagram of the zones in studio:

Anything would help, if you would like me to further elaborate, please ask! Thanks.

Both of these are Horrible ways of checking if a Player is Playing or not,
I would Recommend Creating a Array to insert a List of Players into:

local PlayingPlrs = {}

for _,plr in pairs(game.Players:GetPlayers()) do
    table.insert(PlayingPlrs, plr) -- Adds Players to the Table for Playing
    plr.Character.Humanoid.Died:Connect(function()
        table.remove(PlayingPlrs, PlayingPlrs[plr]) -- Removes Player from Game
    end)
end

I believe this is a good Solution as you can Iterate through PlayingPlrs and Access their Data, Characters, Team, etc. It is also a common way Developers keep track of their Players playing in the game

If you want to check if All Players are dead, you would do:

if #PlayingPlrs < 1 then -- gets the number of Players, if 0 then all Players are dead
    -- code
end

To Remove a Player from the List:

  • Create a Connection for when they die

  • Iterate through Players, check if they are in the table, then remove them

I hope this helps :slight_smile:

1 Like

Thank you very much; I appreciate the fast response time and the willing to help a beginner developer! I believe it is working smoothly after testing it! You saved my project!

1 Like

I would Reccomend looking into these if you are wondering about what they do:

table Library

Tables (or Array’s)

1 Like

Wait, sorry. One more question. My whole minigame system is run on a while true do loop (so the minigame is always running). After a minigame, repeat another one, etc.

So, it’s a server sided script. I am a little confused on how I would use the plr variable (which is the player) in a server script, because it would change the whole server script into a local script.

Idk if this makes sense…

(I’m asking the question because it’s not working anymore for some peculiar reason)

why not just teams, give them the role for being alive when the minigame starts then take it away if they die

How would I do that? I’m not sure how I would start… It sounds a lot easier as well.

Just have 2 Teams : “Alive” and “Dead” for example

When it starts, put every player in a table and give them all the role

Then, if they die, Remove them from the table and give them the Dead role.

1 Like

That way, once it ends, you can check the player for their team, and if they have the alive team, they won the round

1 Like

Using a Table is a lot nicer, plus more Organized, you can iterate through everyone and give them points while with Teams you have to check the team seperately and do so.

It is generally faster and more efficient sometimes.

1 Like

Do you mean this? or something differnet

Dont mess with the for loop here is am idea of what your code should look:

° Intermission
° Add Players to Table (The Code I Gave)
° Start Game Loop

-- while in game Loop:

if #PlayingPlrs < 1 then
   break -- ends game loop
end
-- New Iteration (Game Starts Over)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.