Unable to find player inside a zone

I’m using the zoneplus module right now, and when the player enters a new zone, I want the server to do a sanity check to confirm that the player is actually in that specific zone whenever the remote event is fired.
But for some reason, the server script won’t print out the message. I’ve narrowed down the problem to be because of the if statement in the server script.
if not zone:findPlayer(player) then zone:destroy() return end
Specifically, zone:findPlayer(player) is false, even though the player has indeed entered said zone.

Local script

for _, zone_part in pairs(AncestorContainer:GetChildren()) do
	local zone = Zone.new(zone_part)
	zone.localPlayerEntered:Connect(function()
		NPC_StateChange:FireServer(zone_part) -- player entered a zone, pass through the specific zone part the player entered
	end)
end

Server script

NPC_StateChange.OnServerEvent:Connect(function(player, zone_part)
    print("remote event fired") -- this does print
	-- confirm fired remote event is valid by checking that player is inside the zone on server side
	local zone = Zone.new(zone_part)
	if not zone:findPlayer(player) then zone:destroy() return end
	zone:destroy()
    print("it works") -- this does not print
end)

All of this works perfectly fine when the spawn is located inside a zone but when entering a new zone, it just doesn’t recognize the player is inside another zone.

For context, this is what the zone looks like (the slightly transparent part) and the spawn is located just outside of the part.

1 Like

For some bizarre reason, the server is just unable to detect if a player is inside a zone at all.

function PlayerIsInZone(Playerpos, zone_part) -- this returns false no matter what
	local volumeSpacePoint = zone_part.CFrame:PointToObjectSpace(Playerpos)
	return (math.abs(volumeSpacePoint.X) <= zone_part.Size.X / 2)
		and (math.abs(volumeSpacePoint.Y) <= zone_part.Size.Y / 2)
		and (math.abs(volumeSpacePoint.Z) <= zone_part.Size.Z / 2)
end
	print(math.abs(volumeSpacePoint.X), zone_part.Size.X / 2)
	print(math.abs(volumeSpacePoint.Y), zone_part.Size.Y / 2)
	print(math.abs(volumeSpacePoint.Z), zone_part.Size.Z / 2)

Here’s what the server prints out
image

For some reason volumeSpacePoint.X is just slightly larger than zone_part.Size.X / 2 (the first line in output)

Bump

1 Like

Your current approach seems tedious and overcomplicating, why not just create the zone on the server and listen for playerEntered?

I think your method is convoluted, I also think

local zone = Zone.new(zone_part)
	if not zone:findPlayer(player) then zone:destroy() return end

will trigger the return since you’re making a zone so quickly and then checking findplayer, merely speculation but I don’t think it ever locates the player (its just too quick and doesnt register anything inside zone) thus returns. or the part being received on server is invalid somehow (but then there would be an error so :person_shrugging: )

like another said, just have playerentered on the server side.

sample code in this link: Help needed with Bugged Water system - #17 by Juicy_Fruit

1 Like