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

Detecting players in a block/touching it ?

Asked by 10 years ago

How would I detect the amount of players in a block or between 8 points and check the team color to see if teams are equal or teams unequal. I'm confused on this subject.

0
There are multiple ways of doing this I can think of. You could use Touched and TouchEnded to track touch or FindPartInRegion3 plus getPlayerFromCharacter. Going to implement both and will be right back with the asnwer. Destrings 406 — 10y
0
Try looking at the player's properties. I think "DistanceFromPlayer" would help. GoldenPhysics 474 — 10y

1 answer

Log in to vote
1
Answered by
Destrings 406 Moderation Voter
10 years ago

Implemented this, worked just fine in local server. You could also use FindPartsInRegion3

players = {}

script.Parent.Touched:connect(function(part)
    if part.Parent and part.Parent:FindFirstChild("Humanoid") then
        players[part.Parent.Name] = true
    end
end)

script.Parent.TouchEnded:connect(function(part)
    if part.Parent and part.Parent:FindFirstChild("Humanoid") then
        players[part.Parent.Name] = false
    end
end)

while wait(5) do
    local names = {}
    for k,v in pairs(players) do
        if v then
            table.insert(names, k)
        end
    end
    print(table.concat(names, ", "))
end
Ad

Answer this question