local region = Region3.new(Vector3.new(5,0,5), Vector3.new(15,15,15)) local part = Instance.new("Part") part.Anchored = true part.Size = region.Size part.Parent = game.Workspace part.CanCollide = false part.Transparency = 0.5 while true do wait() local partsInRegion = workspace:FindPartsInRegion3(region, part, 1000) for i, part in pairs(partsInRegion) do if part.Parent:FindFirstChild("Humanoid") ~= nil then print("He's in the region, we got you: "..part.Parent.Name) local char = part.Parent char.Humanoid:TakeDamage(char.Humanoid.MaxHealth) end end end
This Region3 script creates a part and is supposed to, when touched, print the phrase shown above and kill the player, I am following a tutorial by TheDevKing on youtube and I was sure I followed his instructions exactly, can someone please tell me whats wrong, so that I can find a fix? (I posted this yesterday with no answers, please help me guys)
The problem with your code was that the Region
you had created at line 1
was not the same Position
as the hitbox part you had created on line 3
.
I tried creating objects for the Min
and Max
Vector
for the region. That resulted both of them being outside of the hitbox part.
You're now not required to having a hitbox part. You're now defining the Position
, and Size
as a variable at the top.
You're free to remove the code from line 12
to line 18
if you want to. It'll only provide you a means of debugging.
-- Services local playersService = game:GetService("Players") local sizeX, sizeY, sizeZ = 10, 10, 10 local hitboxPosition = Vector3.new(0, 5, 0) local upperCorner = hitboxPosition + Vector3.new(sizeX/2, sizeY/2, sizeZ/2) local lowerCorner = hitboxPosition - Vector3.new(sizeX/2, sizeY/2, sizeZ/2) local region = Region3.new(lowerCorner, upperCorner) local hitbox = Instance.new("Part") hitbox.Parent = workspace hitbox.Anchored = true hitbox.Size = region.Size hitbox.CFrame = region.CFrame hitbox.CanCollide = false hitbox.Transparency = 0.75 while true do local partsInRegion = workspace:FindPartsInRegion3(region, nil, math.huge) for _, part in pairs(partsInRegion) do local player = playersService:GetPlayerFromCharacter(part.Parent) if player then local character = part.Parent local humanoid = character:FindFirstChild("Humanoid") humanoid:TakeDamage(humanoid.MaxHealth) end end wait() end
I think your mistake is about humanoid.As you do in the script,if your humanoid is not nil.Then kill the player and print.Your humanoid might be nil.You can put wait(3) at the start of the script so your humanoid and character can load.