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.
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)--
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!
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
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!
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.
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.
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)