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

How can I make a Script that shows how many people are standing on a brick?

Asked by 10 years ago

Like a gui from Murder Mystery on the map voting.

5 answers

Log in to vote
3
Answered by 10 years ago

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)

Ad
Log in to vote
0
Answered by
Maxomega3 106
10 years ago

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

0
Dang, not only I got ninja'd. I got 1up'ed. You win this time! Maxomega3 106 — 10y
Log in to vote
0
Answered by 10 years ago

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)
0
but how can I make it so when they get off it subtracts that number? PancakeAttacks 0 — 10y
0
You would have to use the TouchEnded function. Try looking it up. joemom33 10 — 10y
Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

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)
0
It's game.Players:GetPlayerFromCharacter, by the way. Thewsomeguy 448 — 10y
0
deprecated method is shorter; stuck with it since it was the first way I saw it used 1waffle1 2908 — 10y
Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

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.

Answer this question