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

How could i make the script not detect keys in chat?

Asked by 2 years ago

i have a script i made that moves you like speed with cframe with making the wasd keys move you with cframe but the problem is when i type in chat it also moves you how could I make this not happen? another issue is the part that goes under the player moves down slowly how could u make this not move at all?

local User = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local GuiService = game:GetService("StarterGui")
local mouse = game.Players.LocalPlayer:GetMouse()

local holdingWKey = false
local holdingSKey = false
local holdingAKey = false
local holdingDKey = false
local holdingSpaceKey = false
local holdingShiftKey = false

local startup = false

Speed_1 = -1
Speed_2 = 1

mouse.KeyDown:connect(function(key)
    if key == "-" then
        Speed_1 = Speed_1 + -0.2
        GuiService:SetCore("SendNotification", {Title = "Speed", Text = "Speed has gone up";})
    end
 end)

mouse.KeyDown:connect(function(key)
    if key == "=" then
        Speed_2 = Speed_2 + 0.2
        GuiService:SetCore("SendNotification", {Title = "Speed", Text = "Speed has gone up";}) 
    end
 end)

 mouse.KeyDown:connect(function(key)
    if key == "[" then
        Speed_1 = Speed_1 + 0.2
        GuiService:SetCore("SendNotification", {Title = "Speed", Text = "Speed has gone down";})
    end
 end)

 mouse.KeyDown:connect(function(key)
    if key == "]" then
        Speed_2 = Speed_2 - 0.2
        GuiService:SetCore("SendNotification", {Title = "Speed", Text = "Speed has gone down";})
    end
 end)










-- player.Character.HumanoidRootPart.Anchored = true


mouse.KeyDown:connect(function(key)
    if key == "h" then
        if startup  == true then
            startup = false
            GuiService:SetCore("SendNotification", {Title = "Speed", Text = "Speed is now disabled";})


        else
            startup = true
            GuiService:SetCore("SendNotification", {Title = "Speed", Text = "Speed is now enabled";})

            local brick = Instance.new("Part", workspace)
            brick.Size = Vector3.new(7, 2, 3)
            brick.CFrame = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame + Vector3.new(0, -4, 0)
            brick.Transparency = 1
            brick.Anchored = true
            brick.Name = "Brick"

            mouse.KeyDown:connect(function(key)
                if key == "h" then
                    brick:remove()
                end
            end)


            for i = 1, math.huge do
                brick.CFrame = game:GetService("Players").LocalPlayer.Character.HumanoidRootPart.CFrame + Vector3.new(0, -4, 0)
                wait(0)
            end
        end
    end
end)





game:GetService('RunService').Stepped:connect(function()
    if startup then
        if WHeld == true then
          game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,Speed_1)
        end
    end
end)

game:GetService('RunService').Stepped:connect(function()
    if startup then
        if SHeld == true then
            game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,Speed_2)
        end
    end
end)

game:GetService('RunService').Stepped:connect(function()
    if startup then
        if AHeld == true then
            game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(Speed_1,0,0)
        end
    end
end)


game:GetService('RunService').Stepped:connect(function()
    if startup then
        if DHeld == true then
            game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(Speed_2,0,0)
        end
    end
end)


game:GetService('RunService').Stepped:connect(function()
    if startup then
        if SpaceHeld == true then
            game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(0,Speed_2,0)
        end
    end
end)

game:GetService('RunService').Stepped:connect(function()
    if startup then
        if ShiftHeld == true then
            game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame * CFrame.new(0,Speed_1,0)
        end
    end

end)                    


User.InputBegan:Connect(function(inputObject) 
    if(inputObject.KeyCode==Enum.KeyCode.W) then
        holdingWKey = true WHeld = true
    end

    if(inputObject.KeyCode==Enum.KeyCode.S) then
        holdingSKey = true SHeld = true
    end

    if(inputObject.KeyCode==Enum.KeyCode.A) then
        holdingAKey = true AHeld = true
    end

    if(inputObject.KeyCode==Enum.KeyCode.D) then
        holdingDKey = true DHeld = true
    end
    if(inputObject.KeyCode==Enum.KeyCode.LeftShift) then
        holdingShiftKey = true ShiftHeld = true
    end

    if(inputObject.KeyCode==Enum.KeyCode.Space) then
        holdingSpaceKey = true SpaceHeld= true
    end

    if(inputObject.KeyCode==Enum.KeyCode.W) then
        holdingUKey = true WHeld = true
    end
end)

User.InputEnded:Connect(function(inputObject)
    if(inputObject.KeyCode==Enum.KeyCode.W) then
        holdingWKey = false WHeld = false
    end

    if(inputObject.KeyCode==Enum.KeyCode.S) then
        holdingSKey = false SHeld = false    
    end

    if(inputObject.KeyCode==Enum.KeyCode.A) then
        holdingAKey = false AHeld = false    
    end

    if(inputObject.KeyCode==Enum.KeyCode.D) then
        holdingDKey = false DHeld = false    
    end

    if(inputObject.KeyCode==Enum.KeyCode.LeftShift) then
        holdingShiftKey = false ShiftHeld = false     
    end

    if(inputObject.KeyCode==Enum.KeyCode.Space) then
        holdingSpaceKey = false SpaceHeld = false
    end
end)

3 answers

Log in to vote
0
Answered by 2 years ago

You might wanna use ContextActionService.

Ad
Log in to vote
0
Answered by
enes223 327 Moderation Voter
2 years ago
Edited 2 years ago

You should use "UserInputService" instead of "Mouse.KeyDown" event, on the input began event the second argument, "processed", checks if the input was processed before it reached to the event, the chat and other stuff processes the key before sending it to the event so you can check if the second argument is true, example code:

User.InputBegan:Connect(function(key, proc)
    if proc then
        print("Typing in the chat")
    else
        print("Pressed while playing")
    end
end)
Log in to vote
0
Answered by 2 years ago
UserInputService.InputBegan:Connect(function(key,chat)
     if chat then return end -- this will make it so that if your typing a key in the chat, it wont do anything
end)

Answer this question