So i made this runnign script that work perfectly, or atleast i thought.
im having a bug where once i change the WalkSpeed of the humanoid the normal walk which is made via the animate script of roblox stop playing. i think this script is the problem if you need the animate code its just the roblox 1 with changed IDs.
Normal Movement:
https://gyazo.com/6d479cfa771be5e581817e3b0cc714db
Run Movement:
https://gyazo.com/c060d092cc6293543ca269d681bb3629
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local Store = game:GetService("ReplicatedStorage")
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local Lead = Player:WaitForChild("Lead")
local Stamina = Lead:WaitForChild("Stamina")
local LastTapped = false
local Running = false
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://ID"
local track = Humanoid:LoadAnimation(Anim)
local VectorZero = Vector3.new(0, 0, 0)
local Remotes = Store:WaitForChild("Remotes")
local ForceStop = Remotes.ForceStop
function Animation(Effect)
if Effect == "StartRun" then
track:Play()
track:AdjustSpeed(2)
else
track:Stop()
end
end
Humanoid.StateChanged:Connect(function(old,new)
if new == Enum.HumanoidStateType.Jumping or new == Enum.HumanoidStateType.Freefall then
Animation("Stop")
elseif new == Enum.HumanoidStateType.Landed then
if Running == true then
Animation("StartRun")
end
end
end)
UIS.InputBegan:Connect(function(Key, gameProcessed)
if not gameProcessed then
if not LastTapped then
if Key.KeyCode == Enum.KeyCode.W then
LastTapped = true
wait(.25)
LastTapped = false
end
else
if Running == false then
Running = true
Humanoid.WalkSpeed = Humanoid.WalkSpeed + 22
Animation("StartRun")
spawn(StaminaD)
else
Running = false
Humanoid.WalkSpeed = Humanoid.WalkSpeed - 22
Animation("Stop")
spawn(Regen)
end
end
end
end)
local function Moved()
if (Humanoid.MoveDirection.Magnitude == 0) then
if Running == true then
Running = false
Humanoid.WalkSpeed = Humanoid.WalkSpeed -22
Animation("Stop")
spawn(Regen)
end
end
end
function StaminaD()
while Running do
if Stamina.Value <= 0 then
Running = false
Humanoid.WalkSpeed = Humanoid.WalkSpeed -22
Stamina.Value = 0
Animation("Stop")
spawn(Regen)
break
end
Stamina.Value = Stamina.Value - 10
wait(1)
end
end
function Regen()
while not Running do
if Stamina.Value >= 1000 then
Stamina.Value = 1000
break
end
Stamina.Value = Stamina.Value + 10
wait(1)
end
end
ForceStop.OnClientEvent:Connect(function()
Running = false
Humanoid.WalkSpeed = Humanoid.WalkSpeed - 22
Animation("Stop")
spawn(Regen)
end)
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(Moved)