Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Player count when touch on a pad?

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

2 comments

0

And by “I’m making”, you mean you want us to “make” it for you? Did you at least try making this?

0

based off his negative rep, pretty sure he never attempted it. (probably tried finding it in free models but failed)

2 answers

Some example lines:

p = #game.Players:GetPlayers()
print(p) -- Or display it in a GUI

1 comment

0

I'm not giving you the Touched event. Do that yourself.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.