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

How to make InputEnded event work only when the wanted key is lifted?

The script below is localscript. Sprinting script works fine. but the problem is print("run") will print run multiple time when I only want it to print one time. and game.Workspace.CurrentCamera.FieldOfView = (80-(i*2)) Will work whenever a key(mouse click and other any keyboard key) is clicked. Please fix this.

local player = game.Players.LocalPlayer
local Char = player.Character or player.CharacterAdded:Wait()
local humanoid = Char:WaitForChild("Humanoid") -- Do not use script.Parent.Humanoid, use Char:WaitForChild("Humanoid")
local UserInputService = game:GetService("UserInputService")
local Running = false

UserInputService.InputBegan:Connect(function(Input, gameProcessed)
    if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) and not gameProcessed then
        Running = true
        humanoid.WalkSpeed = 32
print("run")
        for i = 1,5 do
            game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
            wait()
        end
    end
end)
 
UserInputService.InputEnded:Connect(function(Input, gameProcessed)
    if Input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessed then
        Running = false
        humanoid.WalkSpeed = 16
        if Running == false then
            for i = 1,5 do
                game.Workspace.CurrentCamera.FieldOfView = (80-(i*2))
                wait()
            end
        end
    end
end)

1 answer

For your InputBegan script change it to this

	UserInputService.InputBegan:Connect(function(Input, gameProcessed)
	    if input.KeyCode = Enum.KeyCode.LeftShift and not gameProcessed then
	        Running = true
	        humanoid.WalkSpeed = 32
	print("run")
	        for i = 1,5 do
            game.Workspace.CurrentCamera.FieldOfView = (70+(i*2))
	            wait()
        end
	    end
	end)

you basically do the same as your inputended

1 comment

0

For 2 seconds I thought you put "pun intended", but it just says "inputended"

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