Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I create a game finisher? (I dont know how to say it but click to understand)

Hello, So i have a minigame styled game and I need to figure out how to create a script to know when everyone leaves an area, so it can basically end the game. I had an idea of a way to do this by creating a boolvalue inside of the player and then making it true when the player exits the area (the area is just an invisible cancollide false part engulfing the entire space) and then a masterscript that can find the number of players in the game and basically know at all times if there is anyone inside of the area, and once no one is in it the game ends.

So basically, I think I got the masterscript covered, besides the part where it counts the amount of players in the game. Also it would need to be actively updated every round to know if the amount of players changes. I need some starting help to even begin to understand how to count the players. I do have the boolvalue injector though.

game.Players.PlayerAdded:connect(function(plr)
	local FinishedValue = Instance.new('BoolValue', plr)
	FinishedValue.Name = 'FinishedValue'
	
end)

Thank you for reading, if this sounds like a request, please let me know in the replies so I can somehow word it differently.

1 comment

0

I do not need a full script, but maybe just some hints and good variables and things to use when creating this? Just to get me started

1 answer

✓ Accepted answer

I think there is a better way than this. You can check if any of the players are inside the area by using their Vectors

AreaPosition = --Get the position of the floor of the area
AreaSize = --Get the size of the floor of the area

local function check()
	local count = 0 --Will increase if the script finds a plr in the area
	for _, plr in pairs(game.Player:GetChildren()) do --For every player in the game
		local PlrPos = plr.Character.HumanoidRootPart.Position
		if PlrPos.X < AreaPosition.X + (AreaSize.X/2) and PlrPos.X > AreaPosition.X - (AreaSize.X/2) and PlrPos.Y < AreaPosition.Y + (AreaSize.X/2) and PlrPos.Y > AreaPosition.Y - (AreaSize.X/2) then --If their character is inside the area
			count = count + 1
		end
	end
	return count --return amount of players in the area
end

local PlayersInTheArea = check()

1 comment

0

Thank you! This opens my eyes to more ways of accomplishing my end goal. I will take your ideas into consideration to try and create something.

This discussion is preserved as it was. New answers, comments, and votes are closed.