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

(?) Ignore jump while holding shift script is not working, It was my first script.

Asked by 6 years ago
Edited 6 years ago

Here is my script. It suppost to be like when you hold "Shift" you wont be able to jump.

local player = game.Players.LocalPlayer;
player:GetMouse().KeyDown:connect(function (key)
if key == "Shift" then
humanoid.Jumping:connect(function()
humanoid.Jump = false;
end
end)
player:GetMouse().KeyUp:connect(function (key)
if key == "Shift" then
humanoid.Jumping:connect(function()
humanoid.Jump = true;
end
end)

Can anyone help me with finishing this script and explain please?

0
This method of keyboard input is deprecated Programical 653 — 6y
0
Deprecated. animelover6446 41 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

There's a few issues here. Firstly, GetMouse is deprecated if I'm correct. Secondly, the 'connect' is put after the if. In short, after they click shift once, then when they jump they will be forced to keep jumping, because BOTH pieces have been connected. A better way to go about this is:

--This code only works on a non fe game. Local script under starterpack or startergui
local player = game.Players.LocalPlayer
local allowed = true
local function onKeyPress(inputObject, gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.LeftShift  or inputObject.KeyCode == Enum.KeyCode.RightShift then
        allowed = false
    end
end
local function onKeyLeft(inputObject, gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.LeftShift  or inputObject.KeyCode == Enum.KeyCode.RightShift then
        allowed = true
    end
end
repeat wait() until player.Character ~= nil
player.Character.Humanoid.Jumping:Connect(function()
    if not allowed then
        player.Character.Humanoid.Jump = false
    end
end
game:GetService("UserInputService").InputBegan:Connect(onKeyPress)
game:GetService("UserInputService").InputEnded:Connect(onKeyLeft)

Please accept the answer if it was useful :)

0
Thank you for trying to help me but It is not working, I have put this in Local Script then dragged to StarterGui but its not working, Do I need to do anything else? Anarchizt 0 — 6y
Ad

Answer this question