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

How do I count the number of players touching a part? (Touched event)

Asked by 4 years ago

I am making a map voting system, where there are 3 voting pads, and it should count the number of players standing on each one. I'm just wondering how I can do that.

By the way, please don't just send me some script or send me a whole map voting system script without explaining, as I would like to understand how they work :)

Basically all I want to know is how I can get a count of the number of players touching a part at any given moment.

Thanks

0
You should use onTouch function and value to see how many people stepped onto the pad, if your making a voting system do something simular to do math, if you don't know what any of these mean, research. People don't always give the right answers to certain things so type into google the things I told you you need. ifreakinlostmyacount 52 — 4y

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago

With touched event you can use simple script, it may not be perfect but you can adjust it, its just an example:

local touching = false
local part = script.Parent -- part

part.Touched:Connect(function(hit) -- when touched
    if hit.Parent:FindFirstChild("Humanoid") then -- if human then
        touching = true -- touching
    end
end)

part.TouchEnded:Connect(function() -- when touch ended
    touching = false -- not touching
end)

while wait(1) do
    print(touching)
end
0
Cool, can I ask why you used a while loop to print the value of touching? JGBlocky 9 — 4y
0
Don't use it, it is just an example so you can better see if he is touching so you can be sure, printing is really good for learning. Remove that in-game it's just for the explanation. ) imKirda 4491 — 4y
0
Why inside of a while loop though? Just kinda curious JGBlocky 9 — 4y
0
because every second it will print out if you are on the part or not, it should be more comfortable i guess. imKirda 4491 — 4y
Ad

Answer this question