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

How do I stop UserInputservice whilst typing?

The script below works completely fine but it still works whilst typing, this is REALLY irritating..how do I stop this?

Player = game.Players.LocalPlayer

Player.CharacterAdded:connect(function(Character)

	enabled = true
	enabled2 = true
		
	able = script.able
	local function onInputObject(inputObject,gameProcessed)
		if inputObject.KeyCode == Enum.KeyCode.M then
				if enabled2 == false or able.Value == false then
					return
				end
				
				enabled2 = false
				
				if enabled == true then
					enabled = false
					
					script.Parent:TweenPosition(UDim2.new(0.245, 0, 0, 0), "Out", "Quad", 1)

				elseif enabled == false then
					enabled = true				
					
					script.Parent:TweenPosition(UDim2.new(0.245, 0, -1.4, 0), "In", "Quad", 1)
				end
				
				enabled2 = true
		end		
	end	
game:GetService("UserInputService").InputBegan:connect(onInputObject)
end)

1 answer

✓ Accepted answer

Check if gameProcessedEvent is false

It's either true or false, I believe it's false.

Example,

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameprocess)
	if (inputObject.KeyCode == Enum.KeyCode.M) and (not gameprocess) then
		print("Not typing")
	else
		print("Typing")
	end
end)

Your code,

Applying this information, we get the following code,

local Player = game.Players.LocalPlayer

Player.CharacterAdded:connect(function(Character)

    enabled = true
    enabled2 = true

    able = script.able
    local function onInputObject(inputObject,gameProcessed)
        if (inputObject.KeyCode == Enum.KeyCode.M) and (not gameProcessed) then
                if enabled2 == false or able.Value == false then
                    return
                end

                enabled2 = false

                if enabled == true then
                    enabled = false

                    script.Parent:TweenPosition(UDim2.new(0.245, 0, 0, 0), "Out", "Quad", 1)

                elseif enabled == false then
                    enabled = true              

                    script.Parent:TweenPosition(UDim2.new(0.245, 0, -1.4, 0), "In", "Quad", 1)
                end

                enabled2 = true
        end     
    end 
game:GetService("UserInputService").InputBegan:connect(onInputObject)
end)
If I have it backwards, do if gameProcessed instead of not gameProcessed

Good Luck!

2 comments

0

Thanks for that

0

No problem :3

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