How to stop from firing when the client is typing

how do i stop from being able to type and block at the same time for example if i typed

“fffff” in chat it would fire the event

local RunS = game:GetService("RunService")
local Blocking = false

local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()

local Stuns = require(game.ReplicatedStorage:WaitForChild("Combat"):WaitForChild("Stuns"))


local UIS = game:GetService("UserInputService")

Char.ChildAdded:Connect(function()
    for i,v in pairs(Stuns) do
        if v ~= "Blocking" then
            if game.Players.LocalPlayer.Character:FindFirstChild(v) then Blocking = false return end
        end
    end
end)

RunS.Heartbeat:Connect(function()

    for i,v in pairs(Stuns) do
        if game.Players.LocalPlayer.Character:FindFirstChild(v) then return end
    end


    if UIS:IsKeyDown(Enum.KeyCode.F) then
        Blocking = true
        if Char:FindFirstChild("Blocking") == nil then
            script:WaitForChild("RemoteEvent"):FireServer("Start")
            end
    else
        Blocking = false
        if Char:FindFirstChild("Blocking") then
            script:WaitForChild("RemoteEvent"):FireServer("Stop")
            end
    end
end)```

you could use the GameProcessedEvent parameter, it detects if you’re typing in chat or doing something else

you could refer here

but how do i use this for IsKeyDown()

local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner").ChatService)

if ChatService:IsFocused() then
     print("Player is typing")
end

instead of using RunService, use InputBegan instead

UserInputService.InputBegan:Connect(function(input, _gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.F then
			--code
		end

		if _gameProcessed then
			print("typing")
		else
			print("not typing")
		end
	end
end)

try it out, and edit this code to see what works for you!

this isnt my script but the guy said that breaks it. Also personally i put (input, gpe) its faster to type lol

i’ll have to look into this do you mean game:GetService?

1 Like

yeah I only typed it there so you understand :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.