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

How to make InputEnded only work on specific key?

local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = script.Parent.Humanoid
UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function()
        if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift)then
                humanoid.WalkSpeed = 32
	game.Workspace.CurrentCamera.FieldOfView = 80
end
end)
 
UserInputService.InputEnded:Connect(function()
	game.Workspace.CurrentCamera.FieldOfView = 70
	humanoid.WalkSpeed = 16
end)

This script make player move faster if shift key is pressed. The problem is whenever I press another key while holding shift, the script ends. How do I only make the script end when I am not holding shift anymore?

1 comment

0

InputEnded(Key, GameProcessed) works.

2 answers

✓ Accepted answer
local Key_Wanted = Enum.KeyCode.LeftShift

local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(Input, gameProcessed)
	if Input.KeyCode == Key_Wanted and not gameProcessed then
		-- do stuff;
	end
end)

UIS.InputEnded:connect(function(Input, gameProcessed)
	if Input.KeyCode == Key_Wanted and not gameProcessed then
		-- undo stuff;
	end
end)

1 comment

0

Thanks. By the way, what does gameProcessed do?

local player = game.Players.LocalPlayer
local Character = player.Character

game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		
		player.Character:WaitForChild("Humanoid").WalkSpeed = 32
		
	end
end)

game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		
		player.Character:WaitForChild("Humanoid").WalkSpeed = 16
		
	end
end)

This should do it

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