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

I tried to change the animation while pressing something but it doesn't change when the other anima?

Asked by 3 years ago

I tried to change the animation while pressing something but it doesn't change when the other animation is running.

I am making a separate run and walk animation, This is my script insidethe "Animate" script from the character:

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local pose = "Standing"
local userinput = game:GetService("UserInputService")
local walkorrun = "http://www.roblox.com/asset/?id=7385075929"

userinput.InputBegan:Connect(function(input, gameprocess)
    if not gameprocess then
        if input.KeyCode == Enum.KeyCode.LeftShift then
            local Player = game.Players.LocalPlayer
            local AnimationTracks = Player.Character.Humanoid:GetPlayingAnimationTracks()-- I am trying to stop the old animation while moving here
            for i, v in pairs(AnimationTracks) do
                v:Stop()
            end
            local animation = Humanoid:LoadAnimation(script.run.WalkAnim)
            animation:Stop()
            animation:Destroy()
            script.run.WalkAnim.AnimationId = "rbxassetid://7386449647" -- changing the animation here
print("RUNNING")
        end
    end
end)
userinput.InputEnded:Connect(function(input, gameprocess)
    if not gameprocess then
        if input.KeyCode == Enum.KeyCode.LeftShift then
                local Player = game.Players.LocalPlayer
                local AnimationTracks = Player.Character.Humanoid:GetPlayingAnimationTracks()
                for i, v in pairs(AnimationTracks) do
                    v:Stop()
                end

            local animation = Humanoid:LoadAnimation(script.run.WalkAnim)
            animation:Stop()
            animation:Destroy()
            script.run.WalkAnim.AnimationId = "rbxassetid://7385075929"-- changing the animation here
print("WALKING")
        end

    end
end)


local userNoUpdateOnLoopSuccess, userNoUpdateOnLoopValue = pcall(function() return UserSettings():IsUserFeatureEnabled("UserNoUpdateOnLoop") end)
local userNoUpdateOnLoop = userNoUpdateOnLoopSuccess and userNoUpdateOnLoopValue

local userEmoteToRunThresholdChange do
    local success, value = pcall(function()
        return UserSettings():IsUserFeatureEnabled("UserEmoteToRunThresholdChange")
    end)
    userEmoteToRunThresholdChange = success and value
end

local userPlayEmoteByIdAnimTrackReturn do
    local success, value = pcall(function()
        return UserSettings():IsUserFeatureEnabled("UserPlayEmoteByIdAnimTrackReturn2")
    end)
    userPlayEmoteByIdAnimTrackReturn = success and value
end

local AnimationSpeedDampeningObject = script:FindFirstChild("ScaleDampeningPercent")
local HumanoidHipHeight = 2

local EMOTE_TRANSITION_TIME = 0.1

local currentAnim = ""
local currentAnimInstance = nil
local currentAnimTrack = nil
local currentAnimKeyframeHandler = nil
local currentAnimSpeed = 1.0

local runAnimTrack = nil
local runAnimKeyframeHandler = nil

local PreloadedAnims = {}

local animTable = {}
local animNames = { 
    idle =  {   
                { id = "http://www.roblox.com/asset/?id=507766666", weight = 1 },
                { id = "http://www.roblox.com/asset/?id=507766951", weight = 1 },
                { id = "http://www.roblox.com/asset/?id=507766388", weight = 9 }
            },
    walk =  {   
        { id = "http://www.roblox.com/asset/?id=7332952929", weight = 10 } 
            }, 
    run =   {
        { id = walkorrun, weight = 10 } 

If you dont still quite understand here's a video: https://gyazo.com/1274c097fc380f06286ab7939701e591

The whole time I was pressing shift after i moved my character, as you can see my character just froze after I pressed shift. That is my problem, by the way I had no errors during the video in the output.

0
the vid doesnt even work sne_123456 439 — 3y
0
Sorry Im gonna try to fix it later RichDiggerW189 2 — 3y

Answer this question