How Can I Get The Players Humanoid?

local player = game.Players.LocalPlayer
local Char = player.Humanoid

local hum = player.Humanoid --This is where im errored at!
local  LiftingAnimation = script.LiftingAnimation
local LiftingAnimationTrack = hum:LoadAnimation(LiftingAnimation)
local Item = script.Parent
Item.Mouse.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()

		local LiftingAnimationTrack = hum:LoadAnimation(LiftingAnimation)
		LiftingAnimationTrack:Play()

		local leaderstats = player.leaderstats
		local Coinstat = leaderstats and leaderstats:FindFirstChild("Coins")
		if Coinstat then
			Coinstat.Value = Coinstat.Value + 1
		end
	end)
end)
2 Likes

Try char.Humanoid or char:WaitForChild('Humanoid')

2 Likes

i got errored on that to its weird.

1 Like

I got confused by the fact you capitalized this variable unlike the others; You can either change char to Char or local Char to local char. I’d recommend the second for consistency.

2 Likes
local hum = player.Humanoid --you're referencing to LocalPlayer.Humanoid

change it to

local hum = char:WaitForChild("Humanoid")
1 Like

While you are correct, there’s more to this than just that. See above for more information.

1 Like

testing right to see if it work i reply back if it works

1 Like

player.Character.Humanoid should work well :slight_smile:

2 Likes

Index nill with (“Humanoid”) it doesnt work

1 Like

Ill try that and reply back when done.

1 Like

18:16:22.203 Players.24kslxckz.Backpack.Weight.LocalScript:2: attempt to index nil with ‘Humanoid’ - Client - LocalScript:2

1 Like

18:16:22.203 Players.24kslxckz.Backpack.Weight.LocalScript:2: attempt to index nil with ‘Humanoid’ - Client - LocalScript:2 doesnt work

1 Like
local player = game.Players.LocalPlayer
local Char = player.Character

local hum = Char:WaitForChild("Humanoid") --This is where im errored at!
local  LiftingAnimation = script.LiftingAnimation
local LiftingAnimationTrack = hum:LoadAnimation(LiftingAnimation)
local Item = script.Parent
Item.Mouse.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		
		local LiftingAnimationTrack = hum:LoadAnimation(LiftingAnimation)
		LiftingAnimationTrack:Play()
		
		local leaderstats = player.leaderstats
		local Coinstat = leaderstats and leaderstats:FindFirstChild("Coins")
		if Coinstat then
			Coinstat.Value = goldStat.Value + 1
		end
	end)
end)
1 Like

I will see if it will workk.
wait a sec.

1 Like

didnt work, i tried it.
lol does not work keep erroring at Humanoid.

1 Like

This should work. If it doesnt idk. lol.

1 Like

i tried it exactly like that.
didnt work.

1 Like

What is the error?? Shouldn’t be doing that.

1 Like

18:18:26.176 Players.24kslxckz.Backpack.Weight.LocalScript:2: attempt to index nil with ‘Humanoid’ - Client - LocalScript:2

1 Like

will do it rn ill reply back. when done

2 Likes