The game detects that the player is not in the chat and when typing he/she makes moves

Hi, I have a code that works to run more realistically by double tapping the W, but when the player is chatting and double taps the W, the character starts running. How could I implement that when the player enters the chat and writes that letter, the code doesn’t detect it and doesn’t run?

local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local Track1
local runs = char:WaitForChild("Running")
local DefaultFOV = 70
local run = false
local lastTime = tick()

-- Función para verificar si el chat está visible
local function isChatVisible()
	local playerGui = player:WaitForChild("PlayerGui")
	local chatFrame = playerGui:FindFirstChild("Chat") and playerGui.Chat:FindFirstChild("Frame")
	return chatFrame and chatFrame.Visible
end

UIS.InputBegan:Connect(function(input, gameProcessed)
	if not gameProcessed and input.KeyCode == Enum.KeyCode.W and not isChatVisible() then
		if char:FindFirstChild("Ragdoll") then return end
		local now = tick()
		local difference = (now - lastTime)

		if difference <= 0.5 then
			run = true
			Track1 = hum:LoadAnimation(script.Run)
			Track1:Play()
			hum.WalkSpeed = 49
			runs.Value = true
			local properties = { FieldOfView = DefaultFOV + 15 }
			local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
			local T = TweenService:Create(game.Workspace.CurrentCamera, Info, properties)
			T:Play()
		end

		lastTime = tick()
	end
end)

UIS.InputEnded:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.W then
		run = false
		if Track1 then
			Track1:Stop()
		end
		hum.WalkSpeed = 16
		runs.Value = false
		local properties = { FieldOfView = DefaultFOV }
		local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
		local T = TweenService:Create(game.Workspace.CurrentCamera, Info, properties)
		T:Play()
	end
end)

Just make sure gameProcessed is not true for the InputEnded event.

1 Like

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