I’m trying to make a running script, which will make player run on certain conditions (When player press Shift key + W/S) But the animation keep resets itself when i press any button.
And when I let go of W/S and still holding Shift, the script thinks I’m still running.
This is the whole thing:
This below is my “Run” script:
-- --Garbage script
local RunSpeed = 40-- ///Set running speed
--//////////////////////////--
local Player = game.Players.LocalPlayer
local Stamina = script.Parent:WaitForChild("CurrentStamina")
local IsSprinting = script.Parent:WaitForChild("IsSprinting")
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild('Humanoid')
local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://10891361825'---////Run Animation ID
RAnimation = Humanoid:LoadAnimation(RunAnimation)
local SoundFX = script.RunSound
--//////////////////////////
local W, S = Enum.KeyCode.W, Enum.KeyCode.S
local Key = Enum.KeyCode.LeftShift
local Camera = workspace.CurrentCamera
local UserInputService = game:GetService("UserInputService")
local function WPressed()
return UserInputService:IsKeyDown(W)
end
local function SPressed()
return UserInputService:IsKeyDown(S)
end
local function ShiftPressed()
return UserInputService:IsKeyDown(Key)
end
local function Input(input, gameProcessedEvent)
if ShiftPressed() then
print("Player is running")
if WPressed() then
RAnimation:Play()
SoundFX:Play()
IsSprinting.Value = true
Player.Character.Humanoid.WalkSpeed = RunSpeed
else if SPressed() then
SoundFX:Stop()
IsSprinting.Value = true
end
end
else
print("Player will not run")
IsSprinting.Value = false
end
end
local function InputEnded(input)
if input.KeyCode == Key then
IsSprinting.Value = false
RAnimation:Stop()
SoundFX:Stop()
print("Player stopped running")
Player.Character.Humanoid.WalkSpeed = 20
end
end
UserInputService.InputBegan:Connect(Input)
UserInputService.InputEnded:Connect(InputEnded)
```