Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

1 comment

0

Still not working. :(

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

This discussion is preserved as it was. New answers, comments, and votes are closed.