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

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

Asked by 6 years ago

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?

0
Playing an event? Just, I'm just gonna exit of this tab. hiimgoodpack 2009 — 6y
0
Really appreciate if you tell me what i am doing wrong not just leave. this is why i posted this Mohawkid14 28 — 6y
0
I cannot help a person if I don't know what they are trying to accomplish. hiimgoodpack 2009 — 6y
0
at least tell me why its not working, or just don't comment back Mohawkid14 28 — 6y
View all comments (5 more)
0
I did tell you why it is not working. "Playing an event?" says it all hiimgoodpack 2009 — 6y
0
be more specific Mohawkid14 28 — 6y
0
Your trying to play an event like it is an animation. hiimgoodpack 2009 — 6y
0
is the animation r15 or r6 make sure you are playing the animation on the correct RigType TheScriptKing 102 — 6y
0
Can you please explain what line 20's variable supposed to do? Mineloxer 187 — 6y

1 answer

Log in to vote
0
Answered by
Mineloxer 187
6 years ago

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)
0
Exactly. hiimgoodpack 2009 — 6y
Ad

Answer this question