Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

2 comments

0

This method of keyboard input is deprecated

0

Deprecated.

1 answer

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

1 comment

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.