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

Be able to move only when you jump?

Asked by 5 years ago
Edited 5 years ago
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?

0
Please use a code block. lunatic5 409 — 5y
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. lunatic5 409 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
Where should this script be? I currently have it in StarterCharacterScripts TheMinerBoi10 0 — 5y
0
also forgot to mention that it's in a local script. TheMinerBoi10 0 — 5y
Ad

Answer this question