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.
01 | local noJump = script.NoJump:Clone() |
02 | script.NoJump:Destroy() |
03 |
04 |
05 | function CharacterSpawned(char) |
06 | local noJ = noJump:Clone() |
07 | noJ.Parent = char |
08 | Delay( 0.2 , function () |
09 | noJ.Disabled = false |
10 | end ) |
11 | end |
12 |
13 | function PlayerEntered(player) |
14 | player.CharacterAdded:connect(CharacterSpawned) |
15 | end |
16 |
17 | for _,v in pairs (game.Players:GetPlayers()) do PlayerEntered(v) end |
18 | game.Players.PlayerAdded:connect(PlayerEntered) |
This second chunk below is the content in the "NoJump" script.
1 | local h = script.Parent:WaitForChild( "Humanoid" ) |
2 |
3 | h.Changed:connect( function () |
4 | h.Jump = false |
5 | end ) |
It is recommended that you disable jumping through the SetStateEnabled function of the Humanoid
object. It would go something like this (in a LocalScript):
1 | Humanoid: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
.
I don't know if this works but, give it a try:
1 | local me = game.Players.LocalPlayer.Character |
2 | me.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false ) |
3 | while me.Humanoid.Sit = = true do |
4 | me.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true ) |
5 | end |
6 | while me.Humanoid.Sit = = false do |
7 | me.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false ) |
8 | end |
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:
01 | local me = game.Players.LocalPlayer |
02 | me.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false ) |
03 | local m = me:GetMouse() |
04 | db = true |
05 | m.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 |
14 | end ) |
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!
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.
01 | game.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 ) |
13 | end ) |