Im trying to make a damage to my gun but whenever i miss it gives me a error
i have tried alot of things trying to fix this issue but nothing is working
heres an piece of the code
function DamageCast()
local humanoid = mouse.Target.Parent:FindFirstChild("Humanoid")
if not humanoid then
return nil
end
if humanoid then
humanoid.Health = humanoid.Health - math.random(40,55)
else
return
end
end
That would mean the parent of the mouse target does not exist. This is possibly because your mouse is not hitting anything at the moment to fix this here’s a modified version of your script:
function DamageCast()
if mouse.Target then
local humanoid = mouse.Target.Parent:FindFirstChild("Humanoid")
end
if not humanoid then
return nil
end
if humanoid then
humanoid.Health = humanoid.Health - math.random(40,55)
else
return
end
end
fyi dont do any of that casting on local scripts OR EVEN DAMAGE THE HUMANOID ON CLIENT. you should connect the mouse data to a remote event and let the server do the raycasting etc.