Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to disable input while chatting?

Asked by 2 years ago

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

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
2 years ago

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.

0
where exactly do I have to put it? Because now I can't crawl anymore iiDark_St4le 19 — 2y
0
replace line 15 by these 2 lines  imKirda 4491 — 2y
Ad

Answer this question