Function Misinterpreting Input Values

I have a function here:

local function damageHandler(dmg, victim, player)
	print(dmg)
	local v = game.Players:GetPlayerFromCharacter(victim)
	local p = game.Players:GetPlayerFromCharacter(player)
	local bonus = p.Bonus.Value
	local Defense = v.Defense.Value
	local died = false
	if (victim.Humanoid.Health - dmg+(dmg*bonus/100)-(dmg*Defense/100)) <= 0 then
		v.leaderstats.Fissions.Value += 1
		p.leaderstats.Disrupts.Value += 1
		died = true
	end
	victim.Humanoid.Health -= (dmg+(dmg*bonus/100)-(dmg*Defense/100))
	print(dmg+(dmg*bonus/100)-(dmg*Defense/100))
	print(dmg)
	print(victim.Humanoid.Health)
end)

and when I use this

if Electrolysis.Value == 100 then
	damageHandler(15,hit.Parent, char)
else
	damageHandler(5,hit.Parent, char)
end

both print 15 for each print besides when there is defence and bonus, but it still applies 15 to the dmg value no matter what.

then in another connection I have

if Electrolysis.Value == 100 then
	damageHandler(25,hit.Parent, char)
else
	damageHandler(15,hit.Parent, char)
end

but it’s printing 20 instead

Anybody know what’s happening?

image
just an image of what is printed
I’ve already tried bindEvents too

Can you give more examples of damages, bonuses, and defenses so we can further diagnose the problem?

I fixed it, very crude but I fired the damage value as a string then used tonumber(dmg) in the function

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.