-
What do you want to achieve?
I want to make it so if the player starts running the walkspeed of the player starts increasing until it reaches 28. But if the player’s movedirection is less than or equal to 0 then it resets the walkspeed of the player back to 10 (10 is the default walkspeed I want for the player when it starts walking.) -
What is the issue?
There are no errors in the output. But when it reaches up to 28 it keeps adding 4 to it. And when the player stops walking it won’t go back to the slowspeed which is 10.
local player = game.Players.LocalPlayer
local Character = player:FindFirstChild("Character")
local humanoid = player.Character:FindFirstChild("Humanoid")
local slowspeed = 10 --starting speed
local addup = 4
local limitedspeed = 28
--humanoid.StateChanged:Connect(function()
-- if humanoid:ChangeState() == Enum.HumanoidStateType.Running and humanoid.MoveDirection >= slowspeed then
-- repeat wait(0.1)
-- print("hello")
-- humanoid.WalkSpeed = humanoid.WalkSpeed +4 --adds four everytime
-- until humanoid.WalkSpeed == limitedspeed --limited speed of car
-- elseif humanoid:GetState() == Enum.HumanoidStateType.None or humanoid.MoveDirection <= slowspeed then
-- humanoid.WalkSpeed = slowspeed --goes back to slowspeed
-- end
--end)
humanoid.Running:Connect(function(Speed)
if Speed > 0.75 and humanoid:GetState() == Enum.HumanoidStateType.Running then
repeat
humanoid.WalkSpeed = humanoid.WalkSpeed + addup
wait(0.4)
until humanoid.WalkSpeed == "28"
humanoid.WalkSpeed = limitedspeed
Speed = 0
elseif humanoid.MoveDirection.Magnitude <= 0 and Speed == 0 and humanoid:GetState() ~= Enum.HumanoidStateType.Running then
print("back")
humanoid.WalkSpeed = slowspeed
end
end)