Like a gui from Murder Mystery on the map voting.
How can I make a Script that shows how many people are standing on a brick?
5 answers
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.
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)
2 comments
but how can I make it so when they get off it subtracts that number?
You would have to use the TouchEnded function. Try looking it up.
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)
2 comments
It's game.Players:GetPlayerFromCharacter, by the way.
deprecated method is shorter; stuck with it since it was the first way I saw it used
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Dang, not only I got ninja'd. I got 1up'ed. You win this time!