Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Dealing less damage from far away?

Hi, I was wondering if it is possible to deal less damage the farther away from a gun. here is my script:

script.Parent.Parent.RemoteEvents.Shoot.OnServerEvent:Connect(function(player, FromP, ToP, ToParent)
	local Dist = (FromP-ToP).magnitude
	print(Dist)
	if ToParent:FindFirstChild("Humanoid") then
		ToParent.Humanoid:TakeDamage(Dist)
	end
end)

2 comments

0

I dont know, maybe if you make a value for distance and look for a value for certain distance

1 answer

✓ Accepted answer

Most likely this would be best be done by defining a few variables here.

First, a maximum distance. At what one point will a shot never reach?

Secondly, defining a maximum damage. If shot at point blank, what would maximum damage be?

You could then use a formula like this figure out the damage:

local Damage = (((maximumDistance-actualDistance)/maximumDistance)*maxDamage);

With that in mind, you may also want to use something like math.min to define a minimum damage. If that's something you want, that is.

I'm sure there are more realistic ways, but at a basic level, this will work.

2 comments

0

Thanks i will try this out now

0

This does work but the damage goes down like a arc

This discussion is preserved as it was. New answers, comments, and votes are closed.