I am trying to make a gun and I am trying to make animations for it too but when finished the script and everything it just comes up with an error saying:

18:02:33.017 - Sp00ked1's Place Number: 281 auto-recovery file was created 18:02:40.787 - Players.Sp00ked1.Backpack.Pistol.gun_LocalScript:8: attempt to index nil with 'WaitForChild' 18:02:40.789 - Stack Begin 18:02:40.789 - Script 'Players.Sp00ked1.Backpack.Pistol.gun_LocalScript', Line 8 18:02:40.790 - Stack End

Script:

local Gun = script.Parent
local Handle = Gun:WaitForChild("Handle")
local Event = Gun:WaitForChild("Event")
local Player = game.Players.LocalPlayer
local Character = Player.Character
repeat wait() until Player.Character -- If I add this or remove it still does same error
local PlayerHumanoid = Character:WaitForChild("Humanoid") -- This is what causes the error
local FireAnim = Gun:WaitForChild("Fire")
local ReloadAnim = Gun:WaitForChild("Reload")
local IdleAnim = Gun:WaitForChild("Idle")
local AnimFireTrack = PlayerHumanoid:LoadAnimation(FireAnim)
local AnimReloadTrack = PlayerHumanoid:LoadAnimation(ReloadAnim)
local AnimIdleTrack = PlayerHumanoid:LoadAnimation(IdleAnim)

local Selected = false
local Mouse = Player:GetMouse()

local canFire = true

local fireRate = math.random(0.2,0.3)

Gun.Equipped:Connect(function(Mouse)
	AnimIdleTrack:Play()
	Selected = true
end)

Gun.Unequipped:Connect(function(Mouse)
	AnimIdleTrack:Stop()
	Selected = false
end)

if Selected then
	Mouse.Button1Down:Connect(function()
		if canFire then
			
			canFire = false

			Event:FireServer("Fire",Mouse.Target)

			wait(fireRate)	
			canFire = true
		end
	end)
end