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

Is it possible to track if a player is standing on a part, and when it steps off?

I am trying to make a platform that checks if multiple players are touching at the same time. What is the simplest way to do that? This is pretty much all I have l:

platform.Touched:connect(function(hit)
	local player  = hit.Parent
	if player.Character:FindFirstChild("RobberMatchTag") then
		local robber = player
		
	end
end)

1 answer

✓ Accepted answer

All you would need to do, is something like this:

Touching={}

platform.Touched:connect(function(hit)
	local Valid=true
	local player = hit.Parent
	if player.Character:FindFirstChild("RobberMatchTag") then
		local robber = player
		for i=1, #Touching do
			if Touching[i]==robber then --Checks if players already touching
				Valid=false
			end
		end
		if Valid==true then
			Touching[#Touching+1]=robber
		end
	end
end)

platform.TouchEnded:connect(function(hit) --removes players from table when they stop touching
	local player = hit.Parent
	if player.Character:FindFirstChild("RobberMatchTag") then
		local robber = player
		for i=1, #Touching do
			if Touching[i]==robber then
			Touching[i]:remove()
		end
	end
end)

I think this should work. If you have any problems please leave a comment below. Hope I helped :P

2 comments

1

Thank you for a really quick answer! :D

1

No prob, glad I could help :P

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