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.

local noJump = script.NoJump:Clone()
    script.NoJump:Destroy()


function CharacterSpawned(char)
    local noJ = noJump:Clone()
    noJ.Parent = char
    Delay(0.2, function()       
        noJ.Disabled = false    
    end)
end

function PlayerEntered(player)
    player.CharacterAdded:connect(CharacterSpawned)
end

for _,v in pairs(game.Players:GetPlayers()) do PlayerEntered(v) end
game.Players.PlayerAdded:connect(PlayerEntered)

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


local h = script.Parent:WaitForChild("Humanoid") h.Changed:connect(function() h.Jump = false end)

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):

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.

Ad
Log in to vote
0
Answered by 6 years ago

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

local me = game.Players.LocalPlayer.Character
me.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
while me.Humanoid.Sit == true do
    me.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
end
while me.Humanoid.Sit == false do
    me.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
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:

local me = game.Players.LocalPlayer
me.Character.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
local m = me:GetMouse()
db = true
m.KeyDown:connect(function(k)
    k = k:lower()
    if k == "e" then --you can set hotkey here
        if db == true then
            if me.Character.Humanoid.Sit == true do
                me.Character.Humanoid.Jump = true
            end
        end
    end
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!

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.

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local hum = char:WaitForChild("Humanoid")
        hum.JumpPower = 0
        hum.Seated:Connect(function(IsSitting)
            if IsSitting then
                hum.JumpPower = 35
            else
                hum.JumpPower = 0
            end
        end)
    end)
end)

Answer this question