Find player in area

Hi, I am making a safe zone area so when they spawn and are in lobby, they get infinite steps, else, if they arent, they get 100 steps. Problem is, is that it is really glitchy right now. How would I fix this? Here is my current code:

local SafeZones = workspace.SafeZones
local plr = game.Players.LocalPlayer
local steps = plr.PlayerGui:WaitForChild("StepsGUI").Frame.TextLabel
local stagetrans = plr.PlayerGui:WaitForChild("StageTransfer").CurrentStage
local mod = plr.PlayerGui:WaitForChild('StoreSteps')
local data = require(mod)

for _,v in pairs(workspace.SafeZones:GetChildren()) do
	v.Touched:Connect(function(hit)
		if hit.Parent == plr.Character then
			steps.Text = "inf"
		end
	end)
	
	v.TouchEnded:Connect(function(hit)
		if hit.Parent == plr.Character then
			steps.Text = tostring(data[stagetrans.Text])
			return
		end
	end)
end

Plus a video:

1 Like

Don’t rely on .Touched as it is inaccurate (for your use-case), instead you should use a module like ZonePlus.

local ZN = --insert zone module 

local SafeZones = workspace.SafeZones
local plr = game.Players.LocalPlayer
local steps = plr.PlayerGui:WaitForChild("StepsGUI").Frame.TextLabel
local stagetrans = plr.PlayerGui:WaitForChild("StageTransfer").CurrentStage
local mod = plr.PlayerGui:WaitForChild('StoreSteps')
local data = require(mod)

for _,v in ipairs(workspace.SafeZones:GetChildren()) do
	local zone = ZN.new(v)
	
	zone.playerEntered:Connect(function(player)
		if player == plr then
			steps.Text = "inf"
		end
	end)

	zone.playerExited:Connect(function(player)
		if player == plr then
			steps.Text = tostring(data[stagetrans.Text])
			return
		end
	end)
end
1 Like

Does not work:


Also for some reason 4 zone modules appear on workspace when test play. Is this intentional?

edit: Fixed it using localPlayerEntered/Exited. Except it doesnt change when the player spawns in the part and walks around in it. Which is what I want it to do. The safe zone is at lobby and so the player spawns in the lobby but the module isn’t picking that up and changing it. Also it somehow breaks when I reset character.