If ALL Players Are Touching The Part

This script should work! (I made it off the top of my head.)

local Players = game.Players:GetPlayers()
local TargetPart = script.Parent
local Counter = Instance.new("IntValue", TargetPart)

TargetPart.Touched:Connect(function(NewPlayer)
    Counter.Value = Counter.Value + 1
    for i = #Players do
        if i == Counter.Value then
            -- Do what you want to happen when all the players are touching the part here!
        end
    end
end)

So to make it work, this needs to be a Script inside the part which all the players need to touch. This should work, again let me know if there’s an error or something like that!

Since none of the code solutions seem to work entirely correctly yet as they all either read for too many parts per player, or only check for the Head, here’s a solution that shouldn’t cause any issues.

local touchpart = workspace:FindFirstChild("PartBeingTouched") --change name here 

touchpart.Touched:Connect(function() 
	--this is only here to insert a TouchInterest so :GetTouchingParts() always works 
end) 

function PlayerTouchCheck() 
	local alltouching = false 
	local players = game.Players:GetPlayers() 
	for _,touching in pairs(touchpart:GetTouchingParts()) do 
		if touching.Parent:IsA("Model") then 
			for i,player in pairs(players) do 
				if player.Character == touching.Parent then 
					table.remove(players,i) 
					if #players == 0 then 
						alltouching = true 
					end 
					break 
				end 
			end 
			if alltouching then 
				return true 
			end 
		end 
	end 
	return #players  
end 

local success = PlayerTouchCheck() 

if type(success) ~= "number" then 
	print("All players are touching the part!") 
else 
	print(success .. " players are NOT touching the part.") 
end 

If you need to do a somewhat constant check, you can combine the last part of the script with a loop like this:

while task.wait(0.5) do 
	if type(PlayerTouchCheck()) ~= "number" then 
		--run code for when all players are touching the part 
	end 
end

I hope this helps out!

2 Likes