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

How to disable input while chatting?

Hi :), I have crawl script that work by pressing on "C" but when im in chat it works too and is kinda annoying. Can someone help update my script to desable the inputs?

local uis = game:GetService("UserInputService")
local crawlAnimation = script:WaitForChild("Crawl")
local crawlIdle = script:WaitForChild("CrawlIdle")
local isCrawling = false
local humanoid = script.Parent:WaitForChild("Humanoid")
local sprintscript = humanoid.Parent.SprintScript
local StarterGui = game:GetService('StarterGui')
local loadedIdleAnim = humanoid:LoadAnimation(script:WaitForChild("CrawlIdle"))
local loadedCrawlAnim = humanoid:LoadAnimation(script:WaitForChild("Crawl"))

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()


uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.C then
		if isCrawling then
			isCrawling = false
			if loadedCrawlAnim then loadedCrawlAnim:Stop() end  
			loadedIdleAnim:Stop()           
			game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 16, 50)
			sprintscript.Disabled = false
			humanoid.HipHeight = 0
			humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
		elseif not isCrawling then
			isCrawling = true   
			loadedIdleAnim = humanoid:LoadAnimation(crawlIdle)
			loadedIdleAnim:Play()           
			game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 4, 0)
			sprintscript.Disabled = true
			humanoid.HipHeight = -2
			humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
			StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		end
	end 
end)

game:GetService("RunService").RenderStepped:Connect(function()

	if not isCrawling then return end
	if humanoid.MoveDirection.Magnitude > 0 then
		if not loadedCrawlAnim then loadedCrawlAnim = humanoid:LoadAnimation(crawlAnimation) end
		if loadedCrawlAnim.IsPlaying == false then loadedCrawlAnim:Play() end   
	else
		loadedCrawlAnim:Stop()
		loadedIdleAnim:Play()
	end
end)

1 answer

✓ Accepted answer

uis.InputBegan:Connect(function(key, isFocused)
    if isFocused then return end


this is all that's required, isFocused is going to be true if user is chatting or if his input is focused on a TextBox for example.

2 comments

0

where exactly do I have to put it? Because now I can't crawl anymore

0

replace line 15 by these 2 lines 

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