How Can I Get The Players Humanoid?

Copy and paste the code that i give you it should work. This one.

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

still doesnt work everybody scripts do not work for some reason.

1 Like

Is this a localscript or a script?

1 Like

Instead of this use

local Char = player.Character or player.CharacterAdded:Wait()

yes it is in a local script. i tried everyones.

close but now its erroring 18:24:41.464 Players.24kslxckz.Backpack.Weight.LocalScript:4: attempt to index nil with ‘WaitForChild’

it did not work 18:28:00.755 Humanoid is not a valid member of Player “Players.24kslxckz” - Client - LocalScript:4

This may be because Character does not exist. Try waiting for it to load like this:

local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:wait()

local hum = Char:WaitForChild("Humanoid")
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)

I’m not sure about the context of this, but this may help

1 Like

Oh, that probably returned the second possibility. This should work.

local player = game.Players.LocalPlayer
player.CharacterAdded:Wait()
local Char = player.Character

This is what I posted above, and you can simply do this:

local Char = player.Character or player.CharacterAdded:Wait()

Also: By that error, why are you trying to get the humanoid off the player?

Post 25 and post 28. I have mentioned it before you reply already. Read carefully.

The script is probably run through the second one and this made the script detect the humanoid as the child of the player, not the character.

Not sure what you meant by that. It will wait until the character is loaded. The script me and you gave above is actually working for me but he encountered the error. This is the more efficient way to define the character I guess.

You can get the humanoid by typing player.Character.Humanoid

I was talking about his reply.

it did not work 18:28:00.755 Humanoid is not a valid member of Player “Players.24kslxckz” - Client - LocalScript:4

Alright, im confused about what happening but I made a script for you. I also noticed that you loaded the same track which confused me at first

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer or Players.PlayerAdded:Wait()
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
local LiftingAnimation = Humanoid:FindFirstChildWhichIsA("Animator"):LoadAnimation(script.LiftingAnimation)

local function Equipped(Mouse)
	Mouse.Button1Down:Connect(function()
		LiftingAnimation:Play()
		
		if LocalPlayer:FindFirstChild("leaderstats") then
			LocalPlayer:FindFirstChild("leaderstats"):WaitForChild("Coins") += 1
		end
	end)
end


script.Parent.Mouse.Equipped:Connect(Equipped)

Ah it has been answered already but just for clarity

local char = player.Character or player.CharacterAdded:Wait() -- Wait for character to load
local hum = char:WaitForChild("Humanoid") -- Wait for humanoid to load.

You have to do this bc things do not load instantly

And remember to test test test when writing long pieces of code.

I did fixed i think:

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

local hum = player.Character.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)

Try using the following code;`

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

local hum = game.Workspace:FindFirstChild(player.Name):FindFirstChild(“Humanoid”) --Fixed
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)`

You’re only getting the Player object, not the Character Model

No clue why it’s not working, but maybe try this?

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:FindFirstChild("Humanoid")

if not Humanoid then
    Character:WaitForChild("Humanoid")
end

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 = Humanoid: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)

i did all of that promise not lying

1 Like

local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()

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 = Coinstat.Value + 1
		end
	end)
end)