Humanoid is not a valid member of Workspace

You can write your topic however you want, but you need to answer these questions:

  1. 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.
  2. What is the issue? Include screenshots / videos if possible!
  3. 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

image

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))

That solved it, however I’m getting a new error:

Script:

		if hit.Name == "Glass" and hit.CanCollide == true or hit.Name == "Glass" and hit.Transparency <  -- line thats giving me the error 1 then
		hit.Transparency = 1
		hit.CanCollide = false
		hit.Anchored = false
		local Holyyy = Instance.new("Sound")
		Holyyy.Name = "Crash"
		Holyyy.SoundId = "rbxassetid://144884907"
		Holyyy.Volume = 1
		Holyyy.Parent = hit
		Holyyy:play()
		wait(1.3)
		hit:remove()
		
		elseif (hit.Name == "NONE" or hit.Name == "NONE" or hit.Name == "none") and not hit:findFirstChild("Bulletproof") then
			if hit.CanCollide == true then
			print'wheel'
		hit.CanCollide = false
		local Hitt_Part = Instance.new("Part", workspace)
		Hitt_Part.FormFactor = "Custom"
		Hitt_Part.TopSurface = 0
		Hitt_Part.BottomSurface = 0
		Hitt_Part.Anchored = true
		Hitt_Part.CanCollide = false
		Hitt_Part.Size = Vector3.new()
		Hitt_Part.CFrame = CFrame.new(tuple[2]) * CFrame.Angles(math.random(0, 360), math.random(0, 360), math.random(0, 360))
		Hitt_Part.BrickColor = BrickColor.new("Black")
		Instance.new("BlockMesh", Hitt_Part).Scale = Vector3.new(0.5, 0.5, 0.5)
		Instance.new("Smoke", Hitt_Part).Opacity = 1
		local Holyy = Instance.new("Sound")
		Holyy.Name = "Cracks"
		Holyy.SoundId = "rbxassetid://151284431"
		Holyy.Volume = 1
		Holyy.Pitch = 2
		Holyy.Parent = Hitt_Part
		
		
		Holyy:play()

I’m not sure if this is still a thing, but sometimes the projectile hits another object that also “disappears” on touch.

Try making sure the “hit” is not nil or the Parent of “hit” is not nil so add this line at the top:

if hit == nil or hit.Parent == nil then return end

As the post above stated, make sure “hit” is not nil.

Also, the first line doesnt seem to be completed.
image
Theres is nothing to compare with hit.Transparency and theres no then so that could be the reason the script is breaking.