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

Why is this jump script not working?

Asked by
drew1017 330 Moderation Voter
8 years ago
UIS = game:GetService('UserInputService')

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.Space then
        game.Players.LocalPlayer.Character.Humanoid.Jump = false
        print'you cant jump boi'
    end
end)

It prints but it does not prevent jumping at all. Ive also tried setting HumanoidStateType to None but that doesen't work either. Could someone fill me in on how i'm supposed to prevent jumping properly?

1 answer

Log in to vote
1
Answered by
KoreanBBQ 301 Moderation Voter
8 years ago

Checking UserInputService will tell you when the player jumps AFTER he jumped, thus not preventing it.

What you should do (and I believe that's what's being done everywhere) is using a function fired with Humanoid.Changed, and every time the Humanoid changes, set Jump to false.

Should look like this:

game.Players.PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(char)
        char:FindFirstChild("Humanoid").Changed:connect(function()
            char.Humanoid.Jump=false
        end)
    end)
end)

Didn't test it but I think it should work.

__

If you want it inside a LocalScript,

local plr=script.Parent.Parent
local hum=plr.Character:FindFirstChild("Humanoid")
hum.Changed:connect(function()
hum.Jump=false
end)

Just put that inside a LocalScript inside StarterGui/StarterPack

0
Doesn't work and doesn't print anything if I put a print in it. drew1017 330 — 8y
0
I tested it and it worked. Make sure it's in a normal Script inside workspace and its not disabled. KoreanBBQ 301 — 8y
0
Any way I could apply this in a LocalScript? drew1017 330 — 8y
0
And by the way, the right way to print is: print("what you want to print here") or print('what you want to print here') KoreanBBQ 301 — 8y
View all comments (9 more)
0
Updated my reply with the way to do it for a LocalScript KoreanBBQ 301 — 8y
0
Out of curiosity, my setup was http://i.imgur.com/5fGZIsZ.png, which im pretty sure is identical to that. Why isnt mine working? drew1017 330 — 8y
0
Your print wont work because it's not written appropriately. As for the jump part it really should work, remove what you've written before about UserInputServcice. KoreanBBQ 301 — 8y
0
Also your code doesen't work either. drew1017 330 — 8y
0
And that IS the correct way to print. Ive done it before in the same way with a string. drew1017 330 — 8y
0
Oh my bad that printing method does work. Sorry didn't know about it. 1sec I'll test the method with the Local Script. I DID test the global script way tho, and it worked for me. KoreanBBQ 301 — 8y
0
Yep, the Local Script way did work. Just literally try it with ONLY that in your script. KoreanBBQ 301 — 8y
0
Eh i can just use the global drew1017 330 — 8y
0
It works better in a LocalScript tho. Try it, just don't put anything else and put it in StarterPack KoreanBBQ 301 — 8y
Ad

Answer this question