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

can anyone help with animation and tool? or if my script is wrong?

my group is making a restaurant game and i am making a animation and script for if the food is equip and mouse1down/click then the animation will play and the tool will go with it. but the animation does not play. but when i dont equip it and press mouse1 the animation does play. Heres my script:

local animation = Instance.new("Animation")
animation.AnimationId = "https://www.roblox.com/Asset?ID=1069941509"

local trackanimation = nil
local playability = true
function playAnimation(AnimationSource)
    if playability == true then
        local plr = game.Players.LocalPlayer
        trackanimation = plr.Character.Humanoid:LoadAnimation(animation)

        trackanimation.KeyframeReached:connect(function()
            print ('Working')
        end)
        trackanimation:Play()
    end
end

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local waituntilback = script.Parent.Parent.Hamburger.Equipped:connect()

script.Parent.Parent.Hamburger.Equipped:connect(function()
    if not script.Parent.Parent.Hamburger.Equipped:connect() then
        playAnimation(waituntilback) else
        playAnimation()     
    end
end)

any help please?

9 comments

0

Playing an event? Just, I'm just gonna exit of this tab.

0

Really appreciate if you tell me what i am doing wrong not just leave. this is why i posted this

0

I cannot help a person if I don't know what they are trying to accomplish.

0

at least tell me why its not working, or just don't comment back

0

I did tell you why it is not working. "Playing an event?" says it all

0

be more specific

0

Your trying to play an event like it is an animation.

0

is the animation r15 or r6 make sure you are playing the animation on the correct RigType

0

Can you please explain what line 20's variable supposed to do?

1 answer

Your playAnimation() function needs a source to play from. All I see is you giving it an Event as animation(which doesn't work ofcourse) and the call after it, has no arguments. I have also noticed this is really similar to AlvinBlox's animation tutorial, (wink wink).

To fix your issue.

local animation = Instance.new("Animation")
animation.AnimationId = "https://www.roblox.com/Asset?ID=1069941509"

local trackanimation = nil
local playability = true
function playAnimation(AnimationSource)
    if playability == true then
        local plr = game.Players.LocalPlayer
        trackanimation = plr.Character.Humanoid:LoadAnimation(AnimationSource) --AnimationSource as the argument has passed in

        trackanimation.KeyframeReached:Connect(function()
            print ('Working')
        end)
        trackanimation:Play()
    end
end

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

script.Parent.Parent.Hamburger.Equipped:Connect(function()
    playAnimation(animation) --Don't check for events, just call the function.
end)

I did not test this. Another issue that might hit you. What if the player, unequipped? You add this event to the end.

script.Parent.Parent.Hamburger.Unequipped:Connect(function()
	--Code to stop animation
	--Tip: Animation Tracks have :Stop()
end)

1 comment

0

Exactly.

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