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

How else to detect a player in a region3?

Ive been attempting to make an automatic door, and for a long time ive been confused as to why the door is opening and closing back and forth, and ive finally realized its because of how I am detecting if a player in within a region 3. (I can elaborate if you want, but im positive that this detection is the problem)

local func2 = function()
	local list = game.Workspace:FindPartsInRegion3(Region1, TDF)
	for i, v in pairs(list) do
		if v.Parent:FindFirstChild("Humanoid") ~= nil then
			playerfound = true 
		else
			playerfound = false
		end
	end
end

Problem is, I dont know of any other way to detect if a player is within a region 3. And just to clarify I am working off of the players character, so I cant just check if its a child of the player service.

1 comment

0

if v.Name == "HumanoidRootPart" is the best way to check for player as the root part is his main part.

1 answer

✓ Accepted answer

The problem is that the region3 is detecting player's acessories parts and the other parts arround the door with the parts inside the player, Your script sets the playerFound to false because the current part ins't inside a rig , Heres a fixed script :

local func2 = function()
    local list = game.Workspace:FindPartsInRegion3(Region1, TDF)
local found = 0
    for i, v in pairs(list) do
        if v.Parent:FindFirstChild("Humanoid") ~= nil then
        found = found + 1
        end
    end
if found > 0 then
     playerfound = true 
else
     playerfound = false
end

end

Explanation :

When it detects that a part is inside a player rig, It will add 1 to the found variable So, if it is greater than 0, it sets the playerfound to true

That prevents parts that aren't inside rigs to set the playerfound to false

1 comment

0

ah sorry I forgot to accept the answer, thanks for your help.

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