Safe Zone Attribute for Server Logic thumbnail
0 views0 copies0 likes

Safe Zone Attribute for Server Logic

Universal script

Copy it, then test it in your own Studio place.

Combat & movement Verified

Script code

13 lines · 0.6 KB
Download
local Players = game:GetService("Players")local zone = workspace:WaitForChild("SafeZone")while zone.Parent do	local half = zone.Size / 2	for _, player in Players:GetPlayers() do		local root = player.Character and player.Character:FindFirstChild("HumanoidRootPart")		local point = root and zone.CFrame:PointToObjectSpace(root.Position)		local inside = point ~= nil and math.abs(point.X) <= half.X			and math.abs(point.Y) <= half.Y and math.abs(point.Z) <= half.Z		if player:GetAttribute("InSafeZone") ~= inside then player:SetAttribute("InSafeZone", inside) end	end	task.wait(0.15)end

About this script

Add an anchored box named SafeZone and set CanCollide off. The server checks player root positions against the box in the part's local coordinates, so rotating the box still works. It puts a boolean InSafeZone attribute on each player for your combat or interaction rules to read. Test the corners and the vertical boundary before connecting it to damage logic.

Comments

Share what works, ask questions, or report an issue.

0

Log in to leave a comment.

No comments yet

Be the first to share your thoughts!

Raw Luau source

local Players = game:GetService("Players")
local zone = workspace:WaitForChild("SafeZone")
while zone.Parent do
	local half = zone.Size / 2
	for _, player in Players:GetPlayers() do
		local root = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
		local point = root and zone.CFrame:PointToObjectSpace(root.Position)
		local inside = point ~= nil and math.abs(point.X) <= half.X
			and math.abs(point.Y) <= half.Y and math.abs(point.Z) <= half.Z
		if player:GetAttribute("InSafeZone") ~= inside then player:SetAttribute("InSafeZone", inside) end
	end
	task.wait(0.15)
end