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