Need help with repeating walking animation

so first off this is a link to the game

animation.rbxl (334.3 KB)

i did not make the script i just began learning scripting so this one is just copy and pasted

but the script only plays for a while and than stops

so i want the animation to only play while pressing W but it either stops after a time in the script or continues playing the animation when stopped
heres the script

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local animation = Enum.KeyCode.W --change to the letter you want to use

UIS.InputBegan:Connect(function(key, gp)
	if key.KeyCode == animation then
		if UIS:GetFocusedTextBox() == nil then
			local anim = plr.Character.Humanoid:LoadAnimation(script.Anims.animation)
			anim:Play()
			wait(5)
			anim:Stop()
		end
	end
end)

help is very appreciated

1 Like

“The Code Review category is intended to be a place where developers can get tips to improve already-working code”
– meaning this should be in scripting support (I was surprised this wasn’t solved for an hour)

but anyways, this is in InputBegan

Also, this exist in the script

Consider stopping the animation using InputEnded

Let me know if you need anything else.

1 Like

Quick question, what does this do?

Also, what is gp? it dosen’t seem to be used:

Rough draft of a fixed script, haven’t tested yet but I believe it will work:

local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local animation = Enum.KeyCode.W --change to the letter you want to use

UIS.InputBegan:Connect(function(key, gp)
	if key.KeyCode == animation then
		if UIS:GetFocusedTextBox() == nil then
			local anim = plr.Character.Humanoid:LoadAnimation(script.Anims.animation)
			anim:Play()
		end
	end
end)
UIS.InputEnded:Connect(function(key, gp)
	if key.KeyCode == animation then
		if UIS:GetFocusedTextBox() == nil then
			local anim = plr.Character.Humanoid:LoadAnimation(script.Anims.animation)
			anim:Stop()
		end
	end
end)
2 Likes

alright thanks ill change it this is my first time posting in a script support

i tried using your code and it didint seem to work

heres a video

it does like a weird shuffle aswell its kinda weird

Gp is for game processed event, so basically any key except the input key you want to use.

2 Likes

After watching the video, I come to the conclusion that the animation was never stopped, and the shuffle was caused by two+ animations playing at once…

Not sure why… try simplifying by on ended, remove if UIS:GetFocusedTextBox() == nil then ?

try adding a print statement right after key.KeyCode == animation and see if it will fire

1 Like

still has not worked

could you try to download a copy and see if there is anything wrong with somthing else in it

animation.rbxl (333.9 KB)

I think I figured out the problem, defined anim twice. (I am so idiot lol)

In this line of InputEnded, delete.

1 Like

it still did not work im starting to think it would be best to get a new code

The code given to you will not work because you are loading two different tracks then stopping one that isn’t playing. It will also stutter due to lack of GP checks. Try fixing that first.

If you need help I’ll give you some pointers.

1 Like

Sorry about not making it clear…

you see how it is “local” anim?

local means only in the function… remove the local in the first anim… sorry for making this simple fix take so long…

1 Like

thank you so much dude this fixed it :+1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.