Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to detect how many people are standing on a part?

Asked by 4 years ago

I want to make a surface gui that tell how many people are touching a part at the moment

0
You can create a [Region3](http://https://developer.roblox.com/en-us/api-reference/datatype/Region3), Region3 gets all theparts in the region. By using FindPartsInRegion3WithWhiteList, it'd get all parts that are in the Whitelist, you could use this to detect the number of players in the Region. JoyfulPhoenix 139 — 4y
0
use a touched event, a debounce, a disconnected event and a variable from the server greatneil80 2647 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

well part objects have the Touched and TouchEnded events. you could use this in your favor, like this:

part = workspace.Part
people_standing = 0 -- amount of people on the part

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then -- if a player has touched the part then
        people_standing = people_standing + 1
    end
end)

part.TouchEnded:Connect(function(hit)
    if hit.Parent.FindFirstChild("Humanoid") then -- if a player has quit touching the part then
        people_standing = people_standing - 1
    end
end)
Ad

Answer this question