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