Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to update a run cycle custom animation?

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)

8 comments

0

Please give us a script then i can modified it

0

theres my two scripts controlling it.

0

Couldn't find a solution

0

I would just recommend keep it or make a gui

0

or somehow update this script https://www.youtube.com/watch?v=k8jGv-rCV3M

0

That script won't solve my problem but thanks for your help. I am really bad at explaining my problems...

0

I changed my problem explanation a bit to hopefully make it more clear

0

i think i have a solution

1 answer

✓ Accepted answer

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

1 comment

0

Thanks for all the help

This discussion is preserved as it was. New answers, comments, and votes are closed.