Chat randomly duplicates itself

I have been attempting to create a input system what does not trigger when chatting.
The issue I am currently having is the chat duplicates itself when I try and require the chat module

local Runservice = game:GetService(“RunService”)

local UserInput = game:GetService(“UserInputService”)

local Character = game.Players.LocalPlayer.Character

local Humanoid = Character:WaitForChild(“Humanoid”)

local IsChatting = false

local Dead = false

local Ragdolled = false

UserInput.InputBegan:Connect(function(Input) – Ragdoll stuff goes here

if Input.KeyCode == Enum.KeyCode.F and Ragdolled == false and Dead == false and IsChatting == false then

Ragdolled = true

print(“i am ragdol”)

elseif Input.KeyCode == Enum.KeyCode.F and Ragdolled == true and Dead == false and IsChatting == false then

Ragdolled = false

print(“i am less ragdol”)

end

end)

Humanoid.Died:Connect(function()

if Dead == false and Ragdolled == false then

Dead = true

elseif Dead == false and Ragdolled == true then

Dead = true

end

end)

Runservice.RenderStepped:Connect(function()

local ChatModule = require(game.Chat:WaitForChild(“ChatScript”):WaitForChild(“ChatMain”)) – whenever i try and require the chat it just duplicates it

IsChatting = ChatModule:IsFocused()

end)

How do I prevent this

You don’t need all this extra chat checking code. UserInputService.InputBegan (and its other input events) have a second parameter called gameProcessedEvent. You can simply return from the function early if the value of that is true because it means the event has already been captured by a text box or similar.

Alternatively, you can use ContextActionService which behaves similarly to UserInputService but handles behaviors like these for you.

2 Likes