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

How do I check if only one player is touching a part?

I'm making a round system and I want the round to end if only one player is touching a part. I'm doing like a fighting round game and I need to know when there's only one player in the round and everyone else is in the lobby, So I'm using a part to see if only one player is touching it.

I would appriciate if you say to me how do that and I know that this is not a request forum but I don't know where to put this request so if you have a website or something for me tell me too.

Thanks, MajinBluee

1 comment

0

There are better ways to do this. Try searching up a round tutorial on youtube

1 answer

I don't recommend doing this in your context, there's a lot of better alternatives like keeping an array of active players, and constantly checking the length of the array between an arbitrary interval.

Nonetheless, if you want to get the characters intersecting with a part, you can use the BasePart:GetTouchingParts() method, iterate through the array returned and check for any characters.

Sample code

local part = workspace.Part

local intersectingParts = part:GetTouchingParts()

local playerToCharacterMap = {}

for _, part in pairs(intersectingParts) do
	local player = game.Players:GetPlayerFromCharacter(part.Parent)
	if player and not playerToCharacterMap[player] then
		playerToCharacterMap[player] = part.Parent
	end
end

1 comment

0

How do I get the player to do stuff with him?

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