Help on magnitude damage

does anyone know how I can do damage using magnitude so if someone is in a certain distance of me they take damage?

1 Like

PointA and PointB would be your own and the targets HumanoidRootPart

if (PointA.Position - PointB.Position).Magnitude <= 20 then 
	--// Get the Humanoid and reduce their health 
end
1 Like

I don’t know is this what you want and I’m not a professional scripter but I wanna help
both of my script is in server script and stored in ServerScriptService

You can choose the script you want the first script to only damage the player. And the second script will damage anything that have Humanoids.

First Script Damage To Player Only

local Debounce = false

function damageNearlyPlr(myCharacter, otherCharater, otherHumanoid, otherHumanoidRootPart, myHumanoidRootPart)
	while wait() and otherHumanoid do
		if otherHumanoid and not Debounce and (otherHumanoidRootPart.Position - myHumanoidRootPart.Position).magnitude < 10 then --Change < 10 to something more or less : Less = smaller hitbox more = bigger hitbox
			Debounce = true
			otherHumanoid:TakeDamage(0.1) --Change this for more or less damage
			wait(0.01) --Change this for damage per second
			Debounce = false
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		local allPlr = game.Players:GetPlayers()
		for i, v in pairs(allPlr) do
			if v.Name ~= plr.Name then
				local otherChr = v.Character
				local otherHRP = v:FindFirstChild("HumanoidRootPart")
				local myHRP = chr:FindFirstChild("HumanoidRootPart")
				local otherHum = otherChr:FindFirstChildWhichIsA("Humanoid")
				damageNearlyPlr(chr, otherChr, otherHum, otherHRP, myHRP)
			end
		end
	end)
end)

Second Script Damage To Npc And Player

local Debounce = false

function damageNearlyChr(myCharacter, otherCharater, otherHumanoid, otherHumanoidRootPart, myHumanoidRootPart)
	while wait() and otherHumanoid do
		if otherHumanoid and not Debounce and (otherHumanoidRootPart.Position - myHumanoidRootPart.Position).magnitude < 10 then --Change < 10 to something more or less : Less = smaller hitbox more = bigger hitbox
			Debounce = true
			otherHumanoid:TakeDamage(0.1) --Change this for more or less damage
			wait(0.01) --Change this for damage per second
			Debounce = false
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		local allWorkspaceobjects = workspace:GetDescendants()
		for i, v in pairs(allWorkspaceobjects) do
			if v:IsA("Humanoid") and v ~= chr:FindFirstChildWhichIsA("Humanoid") then
				local otherChr = v.Parent
				local otherHRP = otherChr:FindFirstChild("HumanoidRootPart")
				local otherHum = v
				local myHRP = chr:FindFirstChild("HumanoidRootPart")
				damageNearlyChr(chr, otherChr, otherHum, otherHRP, myHRP)
			end
		end
	end)
end)

I hope this will help you :smiley: