Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

WalkSpeed is instantly increasing?

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

8 comments

0

The LocalScript is placed inside of StarterPlayer > StarterCharacterScripts

0

You have an event inside an infinite loop...

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.

0

@tonicos33 there is no need for the while loop

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'

0

Also use a wait(0.05) or something inside the for loop

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.

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

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.