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

How do I fix a safezone that damages players?

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?

5 comments

2

omg just put on a god damn forcefield when they go in there and remove it when they go out

0

i dont like putting force fields

0

Why not?

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

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.

1 answer

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

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