i made a safezone it work, just wondering what's the best, optimize and efficient
thought player can still exploit by making their client lag and just teleport out before the touchended event manage to delete their forcefield.
function whentouchedOn(hit)
if not hit.Parent or not hit.Parent:FindFirstChild("Humanoid") then return end
if hit.Parent:FindFirstChild("ForceField") then return end
Instance.new("ForceField", hit.Parent)
end
script.Parent.Touched:Connect(whentouchedOn)
function whentouchedOff(hit)
if not hit.Parent or not hit.Parent:FindFirstChild("Humanoid") then return end
if hit.Parent:FindFirstChild("ForceField") then
hit.Parent.ForceField:Destroy()
end
end
for _,v in pairs(script.Parent.allExit:GetChildren()) do
v.TouchEnded:Connect(whentouchedOff)
end
while task.wait(3) do
if script.Parent.CanTouch then
script.Parent.CanTouch = false
else
script.Parent.CanTouch = true
end
end
the while loop is for making sure the people inside the safezone is getting the forcefield, because you know that roblox hitbox when anchored is buggy, so the hitbox either moving or make the cantouch off and on.