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

Player count when touch on a pad? [closed]

Asked by 6 years ago

I'm making a pad that can count how many people are standing on it. It also shown on the screen. Thx!

0
And by “I’m making”, you mean you want us to “make” it for you? Did you at least try making this? User#20279 0 — 6y
0
based off his negative rep, pretty sure he never attempted it. (probably tried finding it in free models but failed) awesomeipod 607 — 6y

Closed as Not Constructive by BlackOrange3343, DeceptiveCaster, and hellmatic

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 6 years ago

Some example lines:

p = #game.Players:GetPlayers()
print(p) -- Or display it in a GUI
0
I'm not giving you the Touched event. Do that yourself. DeceptiveCaster 3761 — 6y
Ad
Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
6 years ago

Try using FindPartsInRegion3WithWhiteList

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local Region = Region3.new(Vector3.new(-100, -100, -100), Vector3.new(100, 100, 100))

local CharacterHeads = {}

local function PlayerAdded(Player)
    local Index

    local function CharacterAdded(Character)
        local Head = Character:FindFirstChild("Head")

        if Head then
            Index = #CharacterHeads + 1
            CharacterHeads[Index] = Head
        end
    end

    CharacterAdded(Player.Character)
    Player.CharacterAdded:Connect(CharacterAdded)

    Player.CharacterRemoving:Connect(function()
        table.remove(Index)
    end)
end

local Playerlist = Players:GetPlayers()
for i = 1, #Playerlist do
    PlayerAdded(Playerlist[i])
end

local function GetPlayersWithinRegion3(Region3ToSearch)
    local Playerlist = Workspace:FindPartsInRegion3WithWhiteList(Region3ToSearch, CharacterHeads, #CharacterHeads)

    for i = 1, #Playerlist do
        Playerlist[i] = Players:GetPlayerFromCharacter(Playerlist[i].Parent)
    end

    return Playerlist
end

table.foreach(GetPlayersWithinRegion3(Region), print)