Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

WalkSpeed is instantly increasing?

Asked by 5 years ago

So what I've done is a script that checks when the player is jumping , and if he is then add more walkSpeed, but if he stops jumping and starts walking again set it back to the original WalkSpeed. Everything is working as intended just that when I reach the max WalkSpeed, stop, and jump again it instantly rises to the max instead of doing it slowly, as intended. Here is the code:

Humanoid = script.Parent.Humanoid
while true do
Humanoid.StateChanged:Connect(function(old , new)
    if new == Enum.HumanoidStateType.Running then
    Humanoid.WalkSpeed = 17 
    --Player is running^
    elseif new == Enum.HumanoidStateType.Jumping then
    Humanoid.WalkSpeed = Humanoid.WalkSpeed + 0.05
    --Player has jumped^
    end
    if Humanoid.WalkSpeed >= 50 then
        Humanoid.WalkSpeed = 50
    end
end)
wait()
end
0
The LocalScript is placed inside of StarterPlayer > StarterCharacterScripts tonicos33 6 — 5y
0
You have an event inside an infinite loop... blockmask 374 — 5y
0
@blockmask well that was the way I knew to do it, do you have any idea what could I change ? I'm not too good at lua as of now. tonicos33 6 — 5y
0
@tonicos33 there is no need for the while loop StrategicPlayZ 58 — 5y
View all comments (4 more)
0
Remove the 'while loop' and add a 'for loop' in the "elseif new == Enum.HumanoidStateType.Jumping then". For e.g: 'for i = 1,10 do Humanoid.WalkSpeed = Humanoid.WalkSpeed + 0.05 end' StrategicPlayZ 58 — 5y
0
Also use a wait(0.05) or something inside the for loop StrategicPlayZ 58 — 5y
0
@StrategicPlayZ I'm not sure about how to use for loops. You see, I want the game to constantly check if the player jumped, and I don't see how can I do that with a for loop. tonicos33 6 — 5y
0
And another problem is that I want the game to add up to the WalkSpeed until it reaches 50. Right now it doesn't add more then 0.05 tonicos33 6 — 5y

1 answer

Log in to vote
0
Answered by
chafava -113
5 years ago
Edited 5 years ago

Put this in a local function so we can use player:

local function answer(player)
      if player.Character.Humanoid.Jump == true then
         player.Character.WalkSpeed = player.Character.WalkSpeed + 1 -- Add 1 walkspeed per jump

end

end

your welcome

ps. if this does not work well i didnt test this script :P

This does not do your function, but close!

Ad

Answer this question