You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to be able to make my guns be able to damage a player.
What is the issue? Include screenshots / videos if possible!
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried solving most parts of the script, but then this error came along the way when I was testing to see if it damages while I tested in-game or not.
if hit.Parent.ClassName ~= "Hat" and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Parent.Humanoid:TakeDamage(settings.basedamage * (settings.headshotm / 2)) -- the line giving the error
targethumanoid = hit.Parent:FindFirstChild("Humanoid")
targettorso = hit.Parent:FindFirstChild("Torso")
elseif hit.Parent.ClassName == "Hat" then
impactm.Transparency = 1
local damagegiven = hit.Parent.Parent.Humanoid:TakeDamage(settings.basedamage * (settings.headshotm / 2))
targethumanoid = hit.Parent.Parent:FindFirstChild("Humanoid")
targettorso = hit.Parent.Parent:FindFirstChild("Torso")
elseif hit:FindFirstChild("vestblock") then
targethumanoid = hit.Parent.Parent:FindFirstChild("Humanoid")
targettorso = hit.Parent.Parent:FindFirstChild("Torso")
end
if targethumanoid and targettorso and targethumanoid.Health > 0 then
in the if statement, you are checking if hit.Parent contains a Humanoid, but right after youre trying to get a Humanoid thats inside hit.Parent.Parent, which in this case is the Workspace. A fix for this would be:
if hit.Parent.ClassName ~= "Hat" and hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(settings.basedamage * (settings.headshotm / 2))
As the post above stated, make sure “hit” is not nil.
Also, the first line doesnt seem to be completed.
Theres is nothing to compare with hit.Transparency and theres no then so that could be the reason the script is breaking.