note: i made the same post 2 weeks ago but i decided to repost it so more people can see it.
So i made a sprint system, it activates when the w and shift key is pressed. But for some reason, in my case, when i pressed shift (only) and let go of the w key and this is after the sprint had started the animations still plays. If anyone could help i would appreciate it!
Here’s the script :
local UIs = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local localPlayer = Players.LocalPlayer
local Animsfolder = game:GetService("ReplicatedStorage").Anims
local runanim = Animsfolder.RunAnim
local character
local Humanoid
local Ranimtrack
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local Properties = { FieldOfView = 80 }
local T = game:GetService("TweenService"):Create(Camera, Info, Properties)
local rProperties = { FieldOfView = 70 }
local rInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local rT = game:GetService("TweenService"):Create(Camera, rInfo, rProperties)
--sprintsetting
local BoolValue = false
local Rspeed = 32
local Nspeed = 16
--
local decreasestamina = false
local stamina = 100
--
local startergui = game:GetService("StarterGui")
local staminagui = startergui:WaitForChild("Stamina")
local whitebar = staminagui:WaitForChild("WhiteBar")
local stamcount = whitebar.StaminaCount
local staminanumbervalue = script.Stamina.Value
--
local function LoadAnimation(char)
character = char
Humanoid = character:WaitForChild("Humanoid")
Ranimtrack = Humanoid:LoadAnimation(runanim)
end
player.CharacterAdded:Connect(LoadAnimation)
--[[
local function CheckWKeyDown()
while true do
Wpressed = UIs:IsKeyDown(Enum.KeyCode.W)
Shiftpressed = UIs:IsKeyDown(Enum.KeyCode.LeftShift)
print(Wpressed)
print(Shiftpressed)
wait()
end
end
--]]
local function Toggle()
if BoolValue then
T:Play()
Ranimtrack:Play()
else
rT:Play()
if Ranimtrack.IsPlaying == true then
Ranimtrack:Stop()
end
end
end
UIs.InputBegan:Connect(function(input, gameProcessed)
if Humanoid.MoveDirection.Magnitude > 0 then
local conditions = (input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false)
while conditions do
Humanoid.WalkSpeed = Rspeed
decreasestamina, BoolValue = true, true
Toggle()
repeat wait() until not BoolValue or conditions
end
end
end)
UIs.InputEnded:Connect(function(input, gameProcessed)
if Humanoid then
if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
Humanoid.WalkSpeed = Nspeed
decreasestamina, BoolValue = false, false
Toggle()
repeat wait() until BoolValue
end
end
end)