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

Script removing ForceField even when I didn't leave the Safe Area?

I have a script below that is supposed to be a "Safe Area", but I'm having multiple issues. First of all, when spawning, players are supposed to get a ForceField but it is very inconsistent. Sometimes I will have one and sometimes I won't. The second issue is players losing their ForceField even when they're still inside the Safe Area. I have tried multiple things, but the current setup is 4 different spawn pads on the top floor of the arena and the Safe Area is a part that covers every single stud of the top floor.

local safearea = script.Parent

safearea.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") and not hit.Parent:FindFirstChild("ForceField") then
		local forcefield = Instance.new("ForceField")
		forcefield.Parent = hit.Parent
		hit.Parent:FindFirstChild("Humanoid").JumpPower = 0
	end
end)

safearea.TouchEnded:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") and hit.Parent:FindFirstChild("ForceField") then
		hit.Parent:FindFirstChild("ForceField"):Destroy()
		hit.Parent:FindFirstChild("Humanoid").JumpPower = 50
	end
end)

5 comments

0

If you'd like i can send an answer with my safezone script and you can alter it.

0

I'd rather you help me fix it but that's fine I guess

0

Does it work if you walk into the area but not spawn into the area?

0

Yes, but like I said the ForceField will randomly go away even when you're inside it.

0

I didn't really wanna do a ForceField, some games just have safe areas where players inside it don't take damage, Ninja Legends is one example. I just don't know how they do it.

1 answer

Try using Region3 instead unless your safezone is a complex shape such as an L and not a Cube or Rectangle. To do more complex shapes u need to do more Region3s

Here’s two ways to use Region3 :

local Pos1 = Vector3.new(32,20,16)
local Pos2 = workspace.Part.Position -- If u want a specific Part to be the position
local Region = Region3.new(Pos1,Pos2)

while wait() do
      local PartsInRegion = workspace:FindPartsInRegion3(Region)
      for _,Part in pairs(PartsInRegion) do
            for _,Player in pairs(game.Players:GetChildren()) do
                  if Part.Name == “HumanoidRootPart” and Part.Parent == Player.Character and not Player.Character:FindFirstChild(“ForceField”) then
                  -- Add forcefield here
                  elseif not Part.Parent == Player.Character  then
                  -- destroy Forcefield here
            end
      end
end

You could always add improvements

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