So uhh im kinda new to module scripts but I made this thing where it does dmg and it sends character to be damaged but for some reason it keeps saying attempt to call a nil value?
-- Snippet of script
hitbox.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") and otherPart.Parent.Name ~= plr.Name then
local char = otherPart.Parent
if char then
dmgModule:Dmg(char,0.1,0.1,script.HitAnim,plr)
end
end
end)
-- Snippet of module script
function dmgModule.Dmg(char,dmg,stunTime,knockback,anim,by)
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
hum:TakeDamage(dmg)
I think the problem here is you’re using a colon instead of a dot…
Using a colon in lua returns self which is used in oop, i fixed it for you in this part of the script.
hitbox.Touched:Connect(function(otherPart)
if otherPart.Parent:FindFirstChild("Humanoid") and otherPart.Parent.Name ~= plr.Name then
local char = otherPart.Parent
if char then
dmgModule.Dmg(char,0.1,0.1,script.HitAnim,plr)
end
end
end)
There were quite a few ways you could have gone about fixing this.
function dmgModule.Dmg(self, char,dmg,stunTime,knockback,anim,by)
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
hum:TakeDamage(dmg)
function dmgModule:Dmg(char,dmg,stunTime,knockback,anim,by)
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
hum:TakeDamage(dmg)