How to Hitbox with Region3

Hello, im trying to make a hitbox, so when anyone touches it they get healed.
I do not want to use the .touched event, i want to use region3, but i do not know anything about region3, can anyone give me a simple code example?

Please dont use a Region3

I am 99.99% sure its deprecated.

this is what it was replaced with!

this is a post from somebody else that explains it, and it has a code example of a spatial query

Good luck!

It works and print’s but, how could i make it so it check’s if the character has humanoid and if it has then, it heals him.

for i,v in pairs(parts_from_query) do
for _,plr in pairs(game.Players:GetPlayers()) do
if v.Parent == plr.Character then
plr.Character.Humanoid.Health += 100
end
end
end

It doesn’t heal, do i need to put a loop?

There’s the code i used:

	local overlapParams = OverlapParams.new()
	
	local partsInPart = workspace:GetPartsInPart(KitHitbox, overlapParams)
	spawn(function()
		while task.wait() do
			for _, part in pairs(partsInPart) do
				for _, plr in pairs(Players:GetPlayers()) do
					if part.Parent == plr.Character then
						print('d')
					end
				end
			end
		end
	end)

I dont know what you mean, but if you are looking to continue healing the player every time they enter the area I would just have a loop for it.
It should work just fine - also there is a function i forgot about game.Players:GetPlayerFromCharacter(character)

could remove a loop of mine

oh yeah you just dont have a heal though right?

What im trying to achieve is mostly a healing kit.
When you touch the hitbox, the kit will be destroyed and the player will heal.

I have a heal function inside the script, i just replaced it to a print.

ohh okay

well if its still not working maybe you need to check if kit and area from inside a loop

Okay, it seems like this worked, and also the loop, thank you!

1 Like