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

How to update a run cycle custom animation?

Asked by 4 years ago
Edited 4 years ago

If I am walking and then I hold shift, I am suppose to start running and the running animation starts playing instead. But what actually happens is when I am walking and then I hold shift I start running but the running animation will not start playing until I stop running for a moment while also holding shift and then running again because the animation is still on the walking animation at the start since it loops forever until you stop walking. How can I make it change instantly instead of having to stop and start again to start the correct animation?

Local Script, Located in PlayerScripts:

Players = game:GetService("Players")
LocalPlayer = Players.LocalPlayer
userInput = game:GetService("UserInputService")

sprinting = false

userInput.InputBegan:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
        sprinting = true
        game.ReplicatedStorage.Sprint:FireServer(LocalPlayer)
    end
end)


userInput.InputEnded:Connect(function(key)
    if key.KeyCode == Enum.KeyCode.LeftShift or key.KeyCode == Enum.KeyCode.RightShift then
        sprinting = false
        game.ReplicatedStorage.Walk:FireServer(LocalPlayer)
    end
end)

Server Script, located in server script service:

game.ReplicatedStorage.Sprint.OnServerEvent:Connect(function(player)
    player.Character.Humanoid.WalkSpeed = 25
    player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://4920166649"
    player.Character.Animate.run.RunAnim.AnimationId = "rbxassetid://4920166649"
end)

game.ReplicatedStorage.Walk.OnServerEvent:Connect(function(player)
    player.Character.Humanoid.WalkSpeed = 16
    player.Character.Animate.walk.WalkAnim.AnimationId = "rbxassetid://4919640169"
    player.Character.Animate.run.RunAnim.AnimationId = "rbxassetid://4919640169"
end)
0
Please give us a script then i can modified it Eric_pokemon 133 — 4y
0
theres my two scripts controlling it. eyeball001 7 — 4y
0
Couldn't find a solution Eric_pokemon 133 — 4y
0
I would just recommend keep it or make a gui Eric_pokemon 133 — 4y
View all comments (4 more)
0
or somehow update this script https://www.youtube.com/watch?v=k8jGv-rCV3M Eric_pokemon 133 — 4y
0
That script won't solve my problem but thanks for your help. I am really bad at explaining my problems... eyeball001 7 — 4y
0
I changed my problem explanation a bit to hopefully make it more clear eyeball001 7 — 4y
0
i think i have a solution Eric_pokemon 133 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I found a answer! so basically you can remove the remote events and the ServerScriptStorage script this script lets you run when you press script and lets you walk when you press control but you can modify it all you want!

here's the script

local script in StarterPlayerScripts

local player = game.Players.LocalPlayer

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(key,_)--run   When input began Basically if the User press Shift they don't have to run while a key
    if key.KeyCode == Enum.KeyCode.LeftShift then
        if player.Character ~= nil then
            player.Character.Humanoid.WalkSpeed = 25
            --add the animation script here
        end
    end
end)

UserInputService.InputBegan:Connect(function(key,_) -- walk When the input end the user doesn't have to hold a key while walking
    if key.KeyCode == Enum.KeyCode.LeftControl then
        if player.Character ~= nil then
            player.Character.Humanoid.WalkSpeed = 16
            --add the animation script here
        end
    end
end)

-- you can remove the remote events and the other script

Sorry i haven't added the animation

0
Thanks for all the help eyeball001 7 — 4y
Ad

Answer this question