luauser-inputrobloxluauroblox-studio

UserInputService isn't detecting inputs


For some reason, my code doesn't work in any way. Does someone has an answer why UserInputService doesn't work for me?

local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local debounce = false

UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, typing)
    print("input")
    if typing then return end
    
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        
        print(player, " pressed lmb")
        
    end
    
end)

I already tried multiple variants of my code, none of which work. For some reason, sometimes, key thingy works, and I can do something by pressing E or Q if I bind it using script. I also tried changing devices, and currently writing this from my Laptop (I mainly do everything on PC.)


Solution

  • The answer was actually, that WaitForChild is better to be used in an if, for example: if not character then character = player:WaitForChild("Character")