So I have a sprint script here, it works fine but when
I start sprinting ( Holding the Shift > W key) but when I let go of the W key the sprint animation still plays. How do I fix this
Video example:
Here’s a part of the code:
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
if humanoid.MoveDirection.Magnitude > 0 then
humanoid.WalkSpeed = RunSpeed
PlayAnim:Play()
tween1:Play()
end
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = DefaultSpeed
PlayAnim:Stop()
tween2:Play()
end
end)
end
end)
There is probably no possible fix for this, this is an issue on the physics end, and you would probably need to make complicated code to fix it.
Plus your still pressing shift so its still playing, just stop it when you stop pressing w or smth if your mad about that lol
(Note: This is a theory, not a fact)
uis.InputEnded:Connect(function(input, gameProccessed)
if input.KeyCode == Enum.KeyCode.LeftShift and not gameProccessed then
humanoid.WalkSpeed = DefaultSpeed
PlayAnim:Stop()
tween2:Play()
end
end)
this will never work becuase InputBegan fires when the key is pressed and passes this key to function means if u press shift and w input parameter will be assigned to Enum.KeyCode.LeftShift but already inside another function Enum.KeyCode.W
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = RunSpeed
PlayAnim:Play()
tween1:Play()
repeat RunService.Heartbeat:Wait()
if humanoid.MoveDirection.Magnitude > 0 then
if not PlayAnim.IsPlaying then
PlayAnim:Play()
end
elseif PlayAnim.IsPlaying then
PlayAnim:Stop()
end
until not uis:IsKeyDown(Enum.KeyCode.LeftShift)
humanoid.WalkSpeed = DefaultSpeed
PlayAnim:Stop()
tween2:Play()
end
end)
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
if humanoid.MoveDirection.Magnitude > 0 then
humanoid.WalkSpeed = RunSpeed
PlayAnim:Play()
tween1:Play()
end
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.W then
humanoid.WalkSpeed = DefaultSpeed
PlayAnim:Stop()
tween2:Play()
end
end)
end
end)
this should help. it didnt work cuz ur not detecting if the player stopped pressing W
local Game = game --Local environment variable.
local UserInput = Game:GetService("UserInputService") --Services.
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid")
local function OnHumanoidRunning(Speed)
if Speed > 0 then
if UserInput:IsKeyDown(Enum.KeyCode.LeftShift) then
--Sprint.
else
--Disable sprint.
end
else
--Disable sprint.
end
end
Humanoid.Running:Connect(OnHumanoidRunning)
You could instead check if the humanoid’s move direction’s magnitude is greater than 0 too.
bro first of all whats the point of doing Game = game ?
also thats a nice use of the sort of forgotten function :IsKeyDown()
also why do you make long variables just abreviate them ya know