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

How can i make this animation play?

Asked by 8 years ago

This is the code I have so far:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local character = Player.Character
local Tools = Player.Backpack
local startgear = Player.StarterGear
local Animation = game.ServerStorage.Animation


function makegearstart()
    for i,v in pairs(Tools:GetChildren()) do 
        v:clone().Parent = startgear
    end
end
makegearstart()

-------------------------------------------
function speed(speed)
    character.Humanoid.WalkSpeed = speed -- speed function
end


function holdingtool()
    for _, child in pairs(character:GetChildren()) do
    if child.ClassName == "Tool" then
     child:remove()
    end
end 
end

function givebacktool()
    for i,v in pairs(startgear:GetChildren()) do 
        v:clone().Parent = Tools
    end
end

Mouse.KeyDown:connect(function(Key) -- main thing
if Key == "x" then 
    if character.Humanoid.WalkSpeed > 0 then
        speed(0)
        Tools:Remove()
        holdingtool()
        Animation:Play()
    else
        speed(16)
        givebacktool()
        Animation:Pause()
    end

end
end)

On the parts where it says "Animation:Play()" and "Animation:Pause()" I cannot get it to play the actual animation. Help?

1 answer

Log in to vote
0
Answered by
AZDev 590 Moderation Voter
8 years ago

My answer has not been tested. Let me know if it works.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local character = Player.Character
local Tools = Player.Backpack
local startgear = Player.StarterGear
local Animation = game.ServerStorage.Animation


function makegearstart()
    for i,v in pairs(Tools:GetChildren()) do 
        v:clone().Parent = startgear
    end
end
makegearstart()

-------------------------------------------
function speed(speed)
    character.Humanoid.WalkSpeed = speed -- speed function
end


function holdingtool()
    for _, child in pairs(character:GetChildren()) do
    if child.ClassName == "Tool" then
     child:remove()
    end
end 
end

function givebacktool()
    for i,v in pairs(startgear:GetChildren()) do 
        v:clone().Parent = Tools
    end
end

local animtrack 

    animtrack = player.Character.Humanoid:LoadAnimation(Animation)

Mouse.KeyDown:connect(function(Key) -- main thing
if Key == "x" then 
    if character.Humanoid.WalkSpeed > 0 then
        speed(0)
        Tools:Remove()
        holdingtool()
        animtrack:Play()
    else
        speed(16)
        givebacktool()
        animtrack:Pause()
    end

end
end)

Ad

Answer this question