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

Jump Prevention

I have a script that will take away 15% of a player's stamina whenever they jump. The only problem is I cannot figure out how to keep players from jumping when they have less than 15% stamina. I have tried humanoid.Jump = falsebut that didn't work. I looked on the wiki for ways to keep a player from jumping, I found UserInputService but I am not quite sure how I would check to see if the localplayer has activated the JumpRequest event.

Here is the code that I am using right now:

wait(1)
local player = game.Players.LocalPlayer
hum = Workspace[player.Name].Humanoid
stamina = player.scores.Stamina

hum.Jumping:connect(function()
	if stamina.Value < 15 then
		hum.Jump = false
	else
		stamina.Value = stamina.Value - 7.5
	end
end)

If somebody could tell me what I am doing wrong and what I could do to fix that I would be very appreciative.

3 comments

0

The reason this wouldn't work is because that .Jumping event fires AFTER the player has already jumped. The .Changed event, on the other hand, fires before they jump, so you can run your stamina check before they can jump.

0

There is a free model that CloneTrooper1019 made.

1

My question had already been answered. I read Frostftw's post and understood that I was doing it at the wrong time. Thanks for explaining it though, chaoticregandpledge.

1 answer

✓ Accepted answer

NOTE TO FUTURE EXPLORERS:

There's a much better (and easier) way to disable Jumping now: set Humanoid.JumpPower to 0.


All you have to do is set the jump to false everytime the humanoid .Changed fires.

local Player = game:service'Players'.LocalPlayer
local Character = Player.Character
local Humanoid = Character:findFirstChild("Humanoid")
Humanoid.Changed:connect(function()
	Humanoid.Jump = false
end)

All this does is disable jumping, if you wish to expand do so.

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