Attempt to index nil with "wait for child"

Keep getting an error for this script:

I marked the error area. The error is: Attempt to index nil with “wait for child”

whats wrong?

local Character
local Player

local Tool = script.Parent

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Stabbed

local Animation = script.Parent.Stab
local StabTrack

local Cooldown = false
local CoolDownTime = 1

Tool.Equipped:Connect(function()
	Character = Tool.Parent 
	Player = game:GetService("Players"):GetPlayerFromCharacter(Character)

	local Humanoid = Character:FindFirstChild("Humanoid")

	if Humanoid then
		StabTrack = Humanoid:LoadAnimation(Animation)
	end
end)

local attacking = false

Tool.Activated:Connect(function()
	if Cooldown == false then
		Cooldown = true
		StabTrack:Play()
		attacking = true
		wait(CoolDownTime)
		Cooldown = false
        attacking = false
	end
end)

Tool.EnhancedCone.Touched:Connect(function(Hit)
if attacking then
	if Hit.Parent then
		if Hit.Parent:FindFirstChild("Humanoid") then
			local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
			local plr = game:GetService("Players")	:GetPlayerFromCharacter(Hit.Parent)
				local vampire = plr:WaitForChild("Classes"):WaitForChild("Vampire")   -- RIGHT HERE <---------
				
				if vampire.Value == true then
					Humanoid.Health -= 100
				else
				Humanoid.Health -= 1
				end	
			end
		end
	end
end)

Make sure that Classes and Vampire actually exist inside of plr. Attempt to index nil with wait for child just means that it can’t find the instance.

It defiantly exists, might be a spelling error on my part then, gtg now put will check later and keep you posted.

1 Like

I was testing the weapon on rigs, and they dont have a player so thats why it did not work.

1 Like