Region3 help AGAIN

I’m genuinely embarrassed of how much I’m using the forum for help but my region3 script isn’t working and I’m trying to make it if you are in the region you die but I’m having trouble with that here is the script,

local workspace = game:GetService("Workspace")


local box = Instance.new("Part")
box.Position = Vector3.new(98.874, 7.5, 213.481)
box.Anchored = true
box.Size = Vector3.new(15,15,15)
box.CanCollide = false
box.Transparency = 0.9
box.Parent = workspace
local region = Region3.new(box.Position - box.Size / 2, box.Position + box.Size / 2)

while true do
	task.wait()
	local partsInRegion = workspace:FindPartsInRegion3(region, box, 1000)

	local found = {}

	for i, part in pairs(partsInRegion) do
		local player = players:GetPlayerFromCharacter(part.Parent)

		if player and not table.find(found, player) then
			table.insert(found, player)

			print("player found in the region!: " .. player.Name)
			part.Parent:FindFirstChild("Humanoid")
			local char = box.Parent
			char.Humanoid:TakeDamage(char.Humanoid.MaxHealth)
		end
	end
end```

What exactly is the problem? Does the script not run? Any errors? Is it just the TakeDamage part? Let me know please :smiley:

It is ok to ask for help in that way you will learn from your mistake.

1 Like

I’ve ran through your script, it seems that you’re parenting the Humanoid to the box area, and the script can’t seem to find the humanoid from there.

Region3 functions are deprecated, I’m not sure if it still works.

Deprecated just means that you shouldn’t use it anymore.

I’ve managed to get it working,

it’s a little buggy, but i’m sure you’ll be able to fix it with a cooldown.

local workspace = game:GetService("Workspace")


local box = Instance.new("Part")
box.Position = Vector3.new(98.874, 7.5, 213.481)
box.Anchored = true
box.Size = Vector3.new(15, 15, 15)
box.CanCollide = false
box.Transparency = 0.9
box.Parent = workspace
local region = Region3.new(box.Position - box.Size / 2, box.Position + box.Size / 2)

while true do
	task.wait()
	local partsInRegion = workspace:FindPartsInRegion3(region, box, 1000)

	local found = {}

	for i, part in pairs(partsInRegion) do
		local player = game.Players:GetPlayerFromCharacter(part.Parent)

		if player and not table.find(found, player) then
			table.insert(found, player)

			print("player found in the region!: " .. player.Name)
			part.Parent:FindFirstChild("Humanoid")
			local char = player.Character
			char.Humanoid:TakeDamage(char.Humanoid.MaxHealth)
		end
	end
end

I know, but it doesn’t necessarily means it completely stopped working, its backends are no longer being improved or updated, but still works but it is discouraged to use so.

Honestly, this is how I use Region3s

So to top it off i have a weird obsession of using RunService over Region3. Anyways, here’s the script which i hope will help you!

local Hit = false
local Timer = 0 -- not required
local Connection;
local Humanoid;
local RegionLifetime = 200 -- not required and you can change the value

Connection = game:GetService(“RunService”).RenderStepped:connect(function() -- use Heartbeat if it’s a server script

if Hit == false then

Timer = Timer + 0.1
if Timer >= RegionLifeTime then
Hit = true Connection:Disconnect()
end

local Region = Region3.new(your part’s region info here)

for i, v in pairs(game.Workspace:FindPartsInRegion3(Region, Ignorelist, MaxParts)) do

if v and v.Parent and v.Parent:FindFirstChild(“Torso”) and v.Parent:FindFirstChild(“HumanoidRootPart”) then
Humanoid = v.Parent:FindFirstChild(“Humanoid”)
end

if Humanoid and Hit == false then
 -- your code here
end
end
end
end)

Thanks the script works now!!! It makes sense and it’s such a little mistake I kind of wished I noticed it from the beginning :sweat_smile:

The script wasn’t working and I didn’t know why