How to damage a player

Yes, I think the hitbox would be succesful, but i can’t try that now.

1 Like

Hey, I am back again, and I have made a hitbox, the only problem is that, I have to find out how to damage the player the closer he is to the center of the hitbox or the lightning point.

Hitbox clip:
robloxapp-20220310-0028087.wmv (3.4 MB)

Thanks once again!

i got an idea, you can try to find the magnitude (basically distance) between the “strike” point and the player with

local distance = (pos1 - pos2).Magnitude

Ooooh, thanks great idea BTW. I will try that, and get back to you.

Actually, need help. How can I apply your code in my code?
My code:

local Position = Vector3.new(0, 1022.5, -15)
local Size = Vector3.new(30, 2048, 30)

local Region = Region3.new(Position-(Size/2),Position+(Size/2))
--local region = Region3.new(Vector3.new(0,0,0),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.9

while true do
   wait()
   local partsinregion = workspace:FindPartsInRegion3(Region)
   for i, part in pairs(partsinregion) do
   	if part.Parent:FindFirstChild("Humanoid") ~= nil then
   		print("Player found in region"..part.Parent.Name)
   		local char = part.Parent
   		char.Humanoid:TakeDamage(char.Humanoid.MaxHealth)
   	end
   end
end

I was thinking to get the player’s position, the position of the center of the “strike point”, then use the formula to get the distance and use the distance as like a reversed multiplier. So the farther away it is, the less damage

Ok, I will just try to implement what you said. I gotta sleep soon lol

So, should I just put the magnitude variable in the take damage function?? I just plugged in the variable, and it doesn’t work

also i think in the code above you are damaging the humanoid multiple times because there is more then one part for each player in the hitbox, the player will get damaged multiple times. I think you should mark off every humanoid you damaged to avoid repeating

how are you implementing this?

Just this code,

–local Position = Vector3.new(0, 1022.5, -15)
–local Size = Vector3.new(30, 2048, 30)

–local Region = Region3.new(Position-(Size/2),Position+(Size/2))

local regionPart = workspace.Hitbox
local pos1 = regionPart.Position - (regionPart.Size / 2)
local pos2 = regionPart.Position + (regionPart.Size / 2)
local region = Region3.new(pos1, pos2)
local magnitude = (pos1 - pos2).Magnitude
–local region = Region3.new(Vector3.new(0,0,0),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.9

while true do
local partsinregion = workspace:FindPartsInRegion3(region)
for i, part in pairs(partsinregion) do
if part.Parent:FindFirstChild(“Humanoid”) ~= nil then
local char = part.Parent
char.Humanoid:TakeDamage(100 * 15 - magnitude)
end
end
end

you need to define magnitude and you should be deciding damage by magnitude because if the player is somehow more than the damage it should take, it wont work.

How? Can you make the variable for the magnitude between the player and the strike point?

I really need help with on how to damage more the closer you are to the part! Please help me ASAP!

Hey, I did what you said, I get a value. BUT the problem is that, I get minus values (Meaning the player would gain health), AND it is not accurate. Any ideas??

Hey, I completed everything, but there is this problem. I few times get negative values for the magnitude(Meaning the player would gain health), and the region3 isn’t accurate. Any ideas? Thanks in advance

Nvm, I fixed it. But Huge thanks to those, who helped me, really appreciate it!

Yes, I noticed that, and I find it anoyying. Can you replace the code? Thanks in advance!

make a new table every time you check for hit detection, add the player in the table once you hit them, and check the table to see if the player you want to hit exists. If so, don’t hit them, and if they have not been hit yet (not in the table) hit them and add them to the table and repeat

I think that will work, I’m still fairly new to this myself

Oh, will try that. But would Break work?