Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I fix a safezone that damages players?

Asked by 5 years ago
Edited 5 years ago

I'm trying to test out some stuff and i made a storm module and its broken because it damages players even if they're in safe zone here's some code if you wanna find out the solution

local function IsInRegion(Player)
for a,b in pairs(workspace:FindPartsInRegion3(Region3FromPart(workspace.World.StormRegion),workspace.World.StormRegion,math.huge)) do

if b.Parent == Player or b.Parent.Parent == Player then

print("Safe")

return true

end

end

print("Damage") --This is for testing

return false

end

Other code

function self:Initialize()
Initialized = true

spawn(function()

while wait(2) do

if not Initialized then break end

for a,b in pairs(game.Players:GetPlayers()) do

if b.Character then

if IsInRegion(b.Character) then

else

b.Character.Humanoid:TakeDamage(math.random(1,5))

end

end

end

end

end)

end

Footage: Photo Any way i can fix it?

2
omg just put on a god damn forcefield when they go in there and remove it when they go out Gameplayer365247v2 1055 — 5y
0
i dont like putting force fields Dalbertjdplayz 37 — 5y
0
Why not? CaptainAlien132 225 — 5y
0
Jesus Christ GamePlayer. Also for ForceFields they have a boolean property called "Visible" that when toggled, changes whether or not the ForceField will be visible to everyone Mr_Unlucky 1085 — 5y
0
FindPartsInRegion3 is resource heavy and by default returns only maximum 20 parts. You may want to increase that limit, or use FindPartsInRegion3WithWhitelist instead, and add characters to that list. However I would just check HumanoidRootPart position on each player instead. Much more efficient. sleazel 1287 — 5y

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
5 years ago
Edited 5 years ago

Forget PartsInRegion3. This will create round safe zone. Let me know if you need a square one.

local SAFE_ZONE_CENTRE = Vector3.new(0,0,0) -adjust to your needs

local function IsInRegion(character) --not player!
    local magnitude = (character.HumanoidRootPart.Position - SAFE_ZONE_CENTRE).magnitude
    if magnitude > 20 then --adjust if necessary
        print(character.Name .. " is being damaged")
        return false
    else --safe
        print(character.Name .. " is safe")
        return true
    end 
end
Ad

Answer this question