Tool Touching Error

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 get a state(like true, false, nil) for the hit.Parent.Humanoid when the tool touches another tool.
  2. What is the issue? Include screenshots / videos if possible!
    The error doesn’t say true, false, or nil. Instead, it says “Stack End - Studio
    18:46:00.751 Humanoid is not a valid member of Tool “Workspace.Dummy.Tool” - Server - Training and Doing Dmg:36” when I test it on a dummy holding a tool.
    Script:
local debounce=false
local damageDebounce=false
local Sword=script.Parent
local Handle=Sword:WaitForChild("Handle")
local Character=Sword.Parent.Parent.Character
local player = game.Players:GetPlayerFromCharacter(Character)
local m6d

Sword.Equipped:Connect(function()
	local a:Weld = Character:FindFirstChild("RightHand"):WaitForChild("RightGrip")
	m6d = Instance.new("Motor6D")
	m6d.Parent = Character:FindFirstChild("RightHand")
	m6d.Name = "RightGrip"
	m6d.Part0 = a.Part0
	m6d.Part1 = a.Part1
	m6d.C0 = a.C0
	m6d.C1 = a.C1
	a:Destroy()
end)

Sword.Unequipped:Connect(function()
	m6d:Destroy()
end)

local slash=script:WaitForChild("slash")
local Strength=player.OV.Strength
local StrMulti=player.OV.StrMulti

Sword.Activated:Connect(function()
	if debounce==false then
		debounce=true
		local slashTrack=player.Character.Humanoid:LoadAnimation(slash)
		slashTrack:Play()
		local Damage=10+(Strength.Value/4)
		Handle.Touched:Connect(function(hit)
			print(hit.Parent.Humanoid)
			if hit.Parent~=Sword.Parent and hit.Parent.Humanoid and damageDebounce==false then
				damageDebounce=true
				hit.Parent.Humanoid:TakeDamage(Damage)
				
			end
		end)
		slashTrack.Stopped:Wait()
		damageDebounce=false
		Strength.Value+=StrMulti.Value
		debounce=false
	end
end)

If it helps, this script is a regular script (not module, local or anything special) and is in a tool placed in the StarterPack
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have searched this on Chrome and the devforum, but haven’t found anything relevant.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

You need to validate and check that the hit’s ancestor has a humanoid .

if not hit.Parent:FindFirsrChild("Humanoid") then return end
1 Like

Thanks so much! I thought that I could just check if it was nil and handle it that way but nope!