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

Be able to move only when you jump?

local play = game.Players.LocalPlayer
local char = play.Character
local hum = char:WaitForChild("Humanoid")

if hum.Jump == true then hum.WalkSpeed = 16
elseif
hum.Jump == false then hum.WalkSpeed = 0

end

I have tried this script:

It doesn't seem to be working, does anyone know what I'm doing wrong?

2 comments

0

Please use a code block.

0

And for the character variable you should be using char = play.Character or play.CharacterAdded:Wait() to ensure that the character has loaded in.

1 answer

###It did work. It only ran once though. You should put the code in an event. Events run each time something is triggered. In this case we will use the Humanoid.Jumping event.

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() -- wait for the character! 
local humanoid = character.Humanoid

humanoid.Jumping:Connect(function(active) -- active is if it's still jumping 
    while active do -- while it's jumping...
        humanoid.WalkSpeed = 16
        wait() -- without this, your script will hang! 
    end
    
    humanoid.WalkSpeed = 0 -- after the while loop breaks, code will run 
end)

###On a side note, always put your code in a code block. You do this by clicking the blue Lua icon and pasting the code in between the tildes. More info on that https://forum.scriptinghelpers.org/topic/82/how-to-format-questions-answers-on-the-main-site.

2 comments

0

Where should this script be? I currently have it in StarterCharacterScripts

0

also forgot to mention that it's in a local script.

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