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

How do I keep a script that disables jump, except for when the player is seated?

Asked by
joeyls 3
6 years ago
Edited 6 years ago

My game has a script called "DisableJump" that has a subscript called "NoJump", which when combined disable jumping in the game. So I am trying to get a tool that requires jumping to work. However, with this script the tool no longer works.

The first chunk below is the content in the "DsiableJump" script.

01local noJump = script.NoJump:Clone()
02    script.NoJump:Destroy()
03 
04 
05function CharacterSpawned(char)
06    local noJ = noJump:Clone()
07    noJ.Parent = char
08    Delay(0.2, function()      
09        noJ.Disabled = false   
10    end)
11end
12 
13function PlayerEntered(player)
14    player.CharacterAdded:connect(CharacterSpawned)
15end
16 
17for _,v in pairs(game.Players:GetPlayers()) do PlayerEntered(v) end
18game.Players.PlayerAdded:connect(PlayerEntered)

This second chunk below is the content in the "NoJump" script.

1local h = script.Parent:WaitForChild("Humanoid")
2 
3h.Changed:connect(function()
4        h.Jump = false
5end)

3 answers

Log in to vote
1
Answered by
nilVector 812 Moderation Voter
6 years ago
Edited 6 years ago

It is recommended that you disable jumping through the SetStateEnabled function of the Humanoid object. It would go something like this (in a LocalScript):

1Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

Then, whenever you want to re-enable jumping, you can simply do the same thing, except set the state enabled to true rather than false.

Ad
Log in to vote
0
Answered by 6 years ago

I don't know if this works but, give it a try:

1local me = game.Players.LocalPlayer.Character
2me.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
3while me.Humanoid.Sit == true do
4    me.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
5end
6while me.Humanoid.Sit == false do
7    me.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
8end

It basically turns off the jumping function and turns it on when you're sitting.

Or if you want instead to jump off the seat by pressing a key do:

01local me = game.Players.LocalPlayer
02me.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
03local m = me:GetMouse()
04db = true
05m.KeyDown:connect(function(k)
06    k = k:lower()
07    if k == "e" then --you can set hotkey here
08        if db == true then
09            if me.Character.Humanoid.Sit == true do
10                me.Character.Humanoid.Jump = true
11            end
12        end
13    end
14end)

I'm 75% sure the "Jump off the seat using a hotkey" script works and 20% on the "Turns off the jumping function and turns it on when you're sitting" script lol

Reply or message me if none of them works or neither of them works, also I'm new to lua so I hope this works!

Log in to vote
0
Answered by
joeyls 3
6 years ago

This is good advice, although, when I tried this "HumanoidStateType" script it wasn't working. However, someone in the discord suggested I use this script, which also allows me to change the jump height essentially, and it would be more preferred for the type of game it is.

01game.Players.PlayerAdded:Connect(function(plr)
02    plr.CharacterAdded:Connect(function(char)
03        local hum = char:WaitForChild("Humanoid")
04        hum.JumpPower = 0
05        hum.Seated:Connect(function(IsSitting)
06            if IsSitting then
07                hum.JumpPower = 35
08            else
09                hum.JumpPower = 0
10            end
11        end)
12    end)
13end)

Answer this question