Like a gui from Murder Mystery on the map voting.
You can use the Touched
and TouchEnded
properties. Touched
to detect stepping on, and TouchEnded
to detect the opposite.
Wiki Pages:
http://wiki.roblox.com/index.php?title=Touched http://wiki.roblox.com/index.php?title=TouchEnded_(Event)
Use a .Touched event to add one to a button, and a .TouchEnded event to take one off if a character steps off.
http://wiki.roblox.com/index.php/TouchEnded
We would do it by setting a value for how many players have touched it. If a player touches it, its value goes up by one, thus telling how many players have touched it (if you wanted it to)
--[[Lets say the bricks name is Hello. we are going to set a variable for hello.]]-- hello = Workspace.Hello plrtouch = 0 hello.Touched:connect(function() plrtouch = plrtouch + 1 print(plrtouch.. " Players have touched this brick.") end)
Use BasePart.Touched
to detect when a character steps on the brick:
local players={} brick.Touched:connect(function(hit) local player=game.Players:playerFromCharacter(hit.Parent) players[player.Name]=true end)
and use BasePart.TouchEnded
to detect when the character steps off:
brick.TouchEnded:connect(function(hit) local player=game.Players:playerFromCharacter(hit.Parent) players[player.Name]=false end)
This is a little complex, but simple once you understand it. And as always, there are multiple ways to do it. I will give you the simplest one.
This is just the idea (no guarantee it will work):
local touching = {} -- Players that are touching local part = script.Parent part.Touched:connect(function(hit) local player = game.Players:playerFromCharacter(hit.Parent) if not player then return end table.insert(touching, player) end) part.TouchEnded:connect(function(hit) local player = game.Players:playerFromCharacter(hit.Parent) if not player then return end for index, touch in pairs(touching) do if player == touch then table.remove(touching, index) end end end)
The code also stores each player, so maybe you can target a certain player or have each player be teleported at a certain time or something. Just an idea. To get the number, just do #touching
.
The other way is much different. The idea is that it searches through all the players and checks the player's distance to the brick. This isn't as accurate as Touch and TouchEnded events.