Hello, i am trying to make a simple script that makes the player sprint, but when in the sprinting state, when i press any keys or mouse buttons it stops the sprinting.
here is an example of what i am talking about
there are no errors, and i believe i have set up the if statements correct, but i might be incorrect
any solutions?
Code
local UIS = game:GetService("UserInputService")
local Sprinting = false
local Anim = script:WaitForChild("Animation"):Clone()
Anim.Parent = character
local SprintAnim = humanoid:LoadAnimation(Anim)
SprintAnim:AdjustSpeed(0.6)
UIS.InputBegan:Connect(function(input, isTyping)
if UIS:IsKeyDown(Enum.KeyCode.W) and UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
if Sprinting == false then
if isTyping then return end
Sprinting = true
humanoid.WalkSpeed = 20
SprintAnim:Play()
end
end
end)
UIS.InputEnded:Connect(function(input, isTyping)
if input.KeyCode == Enum.KeyCode.W or Enum.KeyCode.LeftShift then
if Sprinting == true then
if isTyping then return end
Sprinting = false
humanoid.WalkSpeed = 8
SprintAnim:Stop()
end
end
end)
that was the point of the script, so i didnt have to check if the player had momentum and stop the animation from playing, i had it set so if the player stops holding w then if would stop sprintg
thats what originally did, as you can see in the code i gave, but then problems arise when i try to press any other button while sprinting it stop the sprinting state
It is a weird thing when using or when trying ur code you mean that Enum.KeyCode.LeftShift ~= nil since you didn’t specify what it was related to, so if you said
if text == "aa" or "bb" then
print("ABC")
end
It will always print even if the text wasn’t aa since or "bb" means if bb ~= nil, I should have explained it like that earlier, sry for that.