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)
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
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.
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.
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)
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)
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)
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)