How would I go about using Region3 for Meele

I would like to make a meele using Region3. I have been learning about what region3 is recently and I am starting to get a feeling on how people would use it. I don’t understand how people would use it for meele though. Would they create a region around every character as a hit box and then constantly check if it is being hit? And how would the hitbox detect hit, would it be using touched since whatever touches it damages it? Or magnitude if something is close to it, it damages. Any help will be appreciated. Thanks!

1 Like

Hit is detected in Region3 using a loop and using the FindPartsInRegion3 function! Here is the DevHub post on it.

I didn’t know that. Thank you for telling me

1 Like

Here’s an example of what the script should look like:

script.Parent.RemoteEvent.OnServerEvent:Connect(function(plr)
	local DmgPart = nil --Players hit with this part will be damaged.
	local Region = Region3.new(DmgPart.Position - (DmgPart.Size/2),DmgPart.Position + (DmgPart.Size/2)) --Creates a Region3 that has the same size as DmgPart.
	local Damaged = {} --List of Humanoids that were already damaged. Prevents someone from taking damage twice.
	
	for i,v in pairs(game.Workspace:FindPartsInRegion3(Region,nil,math.huge)) do --Loops through parts that are in the Region
		local Hum = v.Parent:FindFirstChild("Humanoid") or v.Parent.Parent:FindFirstChild("Humanoid")
		
		if Hum and Hum.Health > 0 and Hum.Parent.Name ~= plr.Name and not table.find(Damaged,Hum) then --Checks if there is a Humanoid and if it's alive. Ignores the player if its the attacker or if they have already been damaged.
			table.insert(Damaged,#Damaged + 1,Hum) --Adds the Humanoid to the Damaged table
			Hum.Health = Hum.Health - 100 --Change 100 to the damage that should be dealt
		end
	end
end)

I would also recommend adding a bunch of checks to secure the RemoteEvent.

2 Likes

Wait so will I create a region around the player, and if that player is hit by a certain something it does damage?

That could be done, but I think it’s easier to make a region around the weapon instead of looping through all players.

Hmm I can do that. Thank you for the idea