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

How would one stop a player from jumping?(Partially Solved)

Basically, I am making a script to stop a player from jumping if there 'stamina' is under 15. When I test it in-game, it shows no errors, but doesn't work, so here is the script.

--The script is under the screengui.
local sa=script.Parent.S--A int. value under the screengui.
local fill=script.Parent.Main.Fill--A frame to go over the main part to show visually where your stamina sits.
local hum=script.Parent.Parent.Parent.Character:FindFirstChild("Humanoid")
local txt=script.Parent.Main.TextLabel
coroutine.resume(coroutine.create(function()
while true do
    wait(3)
if sa.Value < 100 then
    sa.Value=sa.Value + 10
elseif sa.Value > 100 then
        sa.Value=100
    end
end
end))

coroutine.resume(coroutine.create(function()
while wait() do
    fill.Size=UDim2.new(sa.Value *0.01, 0, 1, 0)
txt.Text="Stamina:"..sa.Value.."/100"
end
end))

hum.Changed:connect(function()
    if sa.Value >= 15 then
        sa.Value = sa.Value -15
    else --Implying speed is a factor in this
        hum.Jump=false
    end
end)

Thanks in advance. :)

2 answers

The problem is that you're trying to run two while loops at the same time.

--The script is under the screengui.
local sa=script.Parent.S--A int. value under the screengui.
local fill=script.Parent.Main.Fill--A frame to go over the main part to show visually where your stamina sits.
local hum=script.Parent.Parent.Parent.Character:FindFirstChild("Humanoid")

coroutine.resume(coroutine.create(function()
while true do
    wait(3)
if sa.Value < 100 then
    sa.Value=sa.Value + 10
elseif sa.Value > 100 then
        sa.Value=100
    end
end
end))

coroutine.resume(coroutine.create(function()
while wait() do
    fill.Size=UDim2.new(sa.Value *0.01, 0, 1, 0)
end
end))

hum.Changed:connect(function()
    if sa.Value >= 15 then
        sa.Value = sa.Value -15
    else --Implying speed is a factor in this
        hum.Jump=false
    end
end)

11 comments

0

Okay, it allows me to jump now, and it removes stamina, but now it doesn't regen it.

0

It also does not stop me from jumping once it is depleted.

0

You mean the bar or the actual value?

0

The bar, I am not sure about the value, but it won't stop me from jumping anyways, so I assume both.

0

Try now.

0

Great, now, the only problem is that when it is low, I can still jump.

0

I've edited it a small amount, try it again. The if statement might be slowing it down.

0

Still allowed to jump with under 15 stamina.

0

I've just tested it with a value, it may be the bar deceiving you maybe? Do you have a text on it that shows the exact amount of stamina?

0

No, I will add that real quick.

0

Yea, when it is under 15 it doesn't remove stamina, but you still jump, ill edit the question with how I show the value though.

-- You can make your player stop jumping by doing this while true do wait(0.1) game.Workspace.YourNameUwantHere.Humanoid.Jump = false end

1 comment

0

What did I do wrong here?

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