Alright I have a weird bug. Currently I am trying to remove health from a target (in this case a zombie). Yet when I run TakeDamage it kills the player for some reason.
The charT value returns the zombie right before the TakeDamage is run yet the zombie doesn’t take any damage and the player is instantly killed no matter what damage is passed
local charT = script.Target.Value
print(charT) -- Prints Zombie
print(dmg) -- Prints 85
charT.Humanoid:TakeDamage(dmg) --This kills me (The player (Name Daanemark11))
Anyone know why this might be happening?
I’ve tried the many validations but for some reason the damage is just being ran on the wrong target.
Is there anyway you could show us more of the code? It seems like there are some variables outside of this that may need consideration before a conclusion can be made.
function module.DecideDamage(damage, damageType, charType)
--The damage first enetered is 60-100
if charType:FindFirstChild("Info") then
if charType:FindFirstChild("Info"):FindFirstChild("Type").Value == damageType then
local reduced = math.ceil(0.8 * damage)
return reduced
else
return damage
end
else
return damage
end
end
Where if the target has a value info attached to it with the same type as the given type they take reduced damage
local damage = CardTable.GetDamageBasedOnName(script.Parent.Name)
function module.GetDamageBasedOnName(index)
local card = module.ReturnCardByName(index)
local list = card["Amount"]
math.randomseed(tick())
return math.random(list[1], list[2])
end
So it has something to do with dealing more damage than the target has hp for. If I manually enter (24) in the damage dealt. It will run perfectly fine. However, if I set it to 25 (the zombies health). The player is instantly killed.
Though, for some reason dealing damage that brings the target below the hp thresh holds kills the player so instead. If the damage is more than their health it now just removes the target from play and that seems to work.
damage is assigned from the return from GetDameBasedOnName which is 2 items list[1] and list[2]
To me that implies damage is a table containing two items lowest and highest damage so anywhere you use damage you perhaps should refer to damage[1].