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)
“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)
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)
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
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.