Detect How much Players standing in the path/Part

Hello, I made Horror game and Elevator, and I need to detect How much Players standing in the part(with Number) I need script to detect How much Players standing in the part that really Help for me

2 Likes

Do you want a count of how many players are standing in the elevator?

Yes that’s what I mean That really help for me

1 Like

Or you can use Region3’s to detect instances within a box constructed by 2 vectors.

that only Printing 0

image

Cannot replicate, make sure the humanoid root part is within the part.

1 Like

I think this is the simplest way to put it, Put this script in a part that is covering the area, It just tallies up all of the touched events.

local Players_In_Area = 0

script.Parent.Touched:Connect(function(plr)
	local char = plr:FindFirstAncestorWhichIsA("Model")
	
	if game.Players:FindFirstChild(char.Name) then
		Players_In_Area += 1
	end
end)

script.Parent.TouchEnded:Connect(function(plr)
	local char = plr:FindFirstAncestorWhichIsA("Model")

	if game.Players:FindFirstChild(char.Name) then
		Players_In_Area -= 1
	end
end)

i tried it but that detect 2 Players when 1 Player Touching in the Part

Why did you change the brick inside the isInsideBrick function to Florr1?

First of all, you shouldn’t change it at all.

Second, I think your made a typo when you did change it.

You may want to read this: Functions | Roblox Creator Documentation

1 Like

cause I Didn’t saw the Local Part =

You should read the article I linked. Because isTouchingPart is a function, and it’s called with a value, brick is already defined as script.Parent.

If you want to change the part you’re looking at, change the first line of the script, not the stuff inside the functions.

yes, I did it but

that the result

the result still in zero and I did Correct steps

try this it works for me

local Players_In_Area = 0
local plrs = {}

script.Parent.Touched:Connect(function(plr)
	local char = plr:FindFirstAncestorWhichIsA("Model")
	
	if not plrs[char.Name] then
		if game.Players:FindFirstChild(char.Name) then
			plrs[char.Name] = 0
			Players_In_Area += 1
		end
	end
end)

script.Parent.TouchEnded:Connect(function(plr)
	local char = plr:FindFirstAncestorWhichIsA("Model")
	
	if plrs[char.Name] then
		if game.Players:FindFirstChild(char.Name) then
			plrs[char.Name] = nil
			Players_In_Area -= 1
		end
	end
end)

I changed a few things and ts working now

2 Likes

image

there is 1 problem that detect 2 still

oh nvm that work now I Tried 2 script into 1 part that why

show me your explorer and the script inside of it bc it works for me something’s not right

that work now I tried 2 scripts into 1 part

Look