I basically am trying to make my running script not interfere with another animation as you can continue holding down the run button and the animation will continue to play as another animation for a different key bind is playing.
So what I thought of doing was:
if input.KeyCode == Enum.KeyCode.LeftShift or Enum.KeyCode.Q then
player.Character.Humanoid.WalkSpeed = walkSpeed
PlayAnim:Stop()
shift is for ending the run and pressing q is there to stop it from playing during the other animation
However this caused a problem as when any key or mouse clicked is registered it causes the player to slow down.
Why does it end up doing that and how can I fix it?
Bro at least show the whole code bruh cause you declared walkspeed I dont even know what walkspeed is doesnt matter but it helps.Plus is it a script or Local Script
or Enum.KeyCode.Q → or input.KeyCode == Enum.KeyCode.Q
The issue is because in the second part of your conditional statement, you are not comparing anything to Enum.KeyCode.Q, so therefore, as Enum.KeyCode.Q exists, it is returning true for every key you are pressing.
You’ll also want to add gameProcessedEvent into your code as it will register unnecessary inputs when the user is typing in chat.
(UserInputServiceVariable).InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent and input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.Q then
player.Character.Humanoid.WalkSpeed = walkSpeed
PlayAnim:Stop()
Yeah sorry for not providing the whole code here it is:
local UIS = game:GetService('UserInputService')
local Players = game:GetService('Players')
local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()
local sprintSpeed = 40
local walkSpeed = 16
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
player.Character.Humanoid.WalkSpeed = sprintSpeed
local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://10631428562'
PlayAnim = Char.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift or Enum.KeyCode.Q then
player.Character.Humanoid.WalkSpeed = walkSpeed
PlayAnim:Stop()
end
end)
its a local script in startercharacterscript and here is a video of it happening: