My module script can't damage humanoids

  1. What do you want to achieve?
    Make a Damage module script

2.What is the issue?
It works fine for things like checking if there is a humanoid, waiting for cool down, etc. But it won’t damage the Humanoid

  1. What solutions have you tried so far?
    Subtracting the health from the humanoid instead of using :TakeDamage() and using a remote event

Script:
local Dam = {}
Dam.Deal = function(p,c,hit,Damage,cooldown,Charge)
local h = hit.Parent:FindFirstChild(“Humanoid”)
local H = hit.Parent:FindFirstChild(tostring(p.UserId)…“Nen”)
if h and H == nil and hit.Parent ~= c then
print(p,c,hit,Damage,cooldown,Charge)
local H = Instance.new(“BoolValue”,hit.Parent)
H.Name = tostring(p.UserId)…“Nen”
if Charge ~= 0 then
h:TakeDamage(((Damage*Charge)*c.NenDam.Value)c.NenDam.multi.Value)
print(tostring(((Damage
Charge)*c.NenDam.Value)c.NenDam.multi.Value))
else
h:TakeDamage((Damage
c.NenDam.Value)c.NenDam.multi.Value)
print( tostring((Damage
c.NenDam.Value)*c.NenDam.multi.Value))
end
wait(cooldown)
H:Destroy()
end
end
return Dam

p == player
c == Character
hit == hit in the touched event

1 Like

Is this code in a module script? Those are meant to run only once when another actual script uses require.

local somedata = require(SomeModuleScript) --this line would be in a regular script

1 Like

Yeah, it is. Also, the reply needs 30 characters :stuck_out_tongue:

Copy all the code and paste it into a regular script is what I mean.

1 Like

But then it would loose it’s point, the reason it in a module script is so that i can use it multiple times, and change it whenever i want easily.

I don’t think you have the correct idea. Have a look at this.

1 Like

The other script goes like this:
local Damage = require(game.ServerStorage.Damage)

– stuff –

Part.Touched:Connect(function(hit)
Damage.Deal(variables)
end)

– stuff –

end

is there something wrong?

Oh, sorry. I misread some things.

1 Like

Can I see the variables you pass? Also, are there any errors?

1 Like

if it hit a humanoid they would probably be like (your player,your character, body part, 20, 5, 1)
I use player for the cooldown efect;
Character so i can use a few values in it(that will multiply the damage);
Body part,Cooldown and damage for obvious reasons;
And charge is a value that increases when you charge the attack that multiplies it by 1 to 2.

I tried it, and it worked for me (though I did delete the extra charge and NenDam stuff). Good luck, this is probably not a hard fix.

1 Like

Turns out it works if i calculate the damage and give it as a variable instead of doing it afterwards. Sorry for bothering you with such a dumb mistake.