Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Animation won't play through script. How do I fix this?

Asked by 6 years ago
Edited 6 years ago

I'm new to scripting and I'm trying to make it so when you click or "pickup" the grass, an animation plays of you bending down and actually picking it up, but when I click it, the whole script works fine except that it won't play the animation.

Object = script.Parent
Max= 10
Clickey = script.Parent.ClickDetector
Name = "Grass"

function collect(plr)
    local Grass = plr.leaderstats:FindFirstChild(Name)
    local humanoid = plr.Character:WaitForChild("Humanoid")
    local PickupAnim = Instance.new("Animation", humanoid)
    PickupAnim.AnimationId = 'rbxassetid://1595224701'
    local PickupAnimLoaded = humanoid:LoadAnimation(PickupAnim)
    if Grass then
        if Grass.Value >= Max then
            print("You have too much")
            return
        else
            Grass.Value = Grass.Value + 1 
            PickupAnimLoaded:Play()
            return
        end
    end         
end 

Clickey.MouseClick:connect(collect)

2 answers

Log in to vote
0
Answered by 6 years ago
Object = script.Parent
Max= 10
Clickey = script.Parent.ClickDetector
Name = "Grass"

function collect(plr)
    local Grass = plr.leaderstats:FindFirstChild(Name)
    local humanoid = plr.Character:WaitForChild("Humanoid")
09
    local PickupAnim = Instance.new("Animation")
10
    PickupAnim.AnimationId = 'rbxassetid://1595224701'
    PickupAnim.Parent = plr
    local PickupAnimLoaded = humanoid:LoadAnimation(PickupAnim)
    PickupAnim:Play()
    if Grass then
        if Grass.Value >= Max then
            print("You have too much")
            return
        else
            Grass.Value = Grass.Value + 1
            PickupAnimLoaded:Stop()
            return
        end
    end        
end

Clickey.MouseClick:connect(collect)

0
Still not working. :( ProjectJager 62 — 6y
Ad
Log in to vote
0
Answered by
Nonaz_jr 439 Moderation Voter
6 years ago

So I'm guessing this is in a script, while you need to load the animation into an animator if you are not in a localscript.

local PickupAnimLoaded = humanoid.Animator:LoadAnimation(PickupAnim)

or move it to a local script, but then the clickdetector should be accessed by a script not a localscript..

Answer this question