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

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

Asked by
ultrabug 306 Moderation Voter
10 years ago

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

Log in to vote
0
Answered by
Lacryma 548 Moderation Voter
10 years ago

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)
0
Okay, it allows me to jump now, and it removes stamina, but now it doesn't regen it. ultrabug 306 — 10y
0
It also does not stop me from jumping once it is depleted. ultrabug 306 — 10y
0
You mean the bar or the actual value? Lacryma 548 — 10y
0
The bar, I am not sure about the value, but it won't stop me from jumping anyways, so I assume both. ultrabug 306 — 10y
View all comments (7 more)
0
Try now. Lacryma 548 — 10y
0
Great, now, the only problem is that when it is low, I can still jump. ultrabug 306 — 10y
0
I've edited it a small amount, try it again. The if statement might be slowing it down. Lacryma 548 — 10y
0
Still allowed to jump with under 15 stamina. ultrabug 306 — 10y
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? Lacryma 548 — 10y
0
No, I will add that real quick. ultrabug 306 — 10y
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. ultrabug 306 — 10y
Ad
Log in to vote
-4
Answered by 10 years ago

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

0
What did I do wrong here? bigbenbennett 18 — 7y

Answer this question