UserInputService.InputBegan

Hello there,

I am trying to make a player carry system but, UserInputService.InputBegan doesn’t work. It doesn’t even fire. I’m trying to get InputBegan to work but that is really difficult if it doesn’t even fire.

The LocalScript is inside StarterCharacterScripts.

This is the event:

UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping == false then
		if Input.KeyCode == Enum.KeyCode.X then
        -- Code
        end
    end
end)

I have tried everything. Using InputEnded, InputChanged, and even trying to print when the input has begun. I have no idea how to solve this issue.

2 Likes

If anyone wants to know the whole code here it is.

repeat task.wait() until game:IsLoaded()

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")

local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
while Character.Parent ~= nil do
	Character.AncestryChanged:Wait()
end
local Humanoid = Character:WaitForChild("Humanoid")

local Use = script:WaitForChild("Use")

local Throw = script:WaitForChild("Throw")
local PickUp = script:WaitForChild("PickUp")
local Carry = script:WaitForChild("Carry")

local LoadedThrow = Humanoid:LoadAnimation(Throw)
local LoadedPickUp = Humanoid:LoadAnimation(PickUp)
local LoadedCarry = Humanoid:LoadAnimation(Carry)

UserInputService.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping == false then
		if Input.KeyCode == Enum.KeyCode.X then
				--Code
			end
		end
	end
end)


function Carry(Target)
	--Code
end

I found the problem. That minor spelling mistake made the script win the argument.

Instead of doing:

while Character.Parent ~= nil do
	Character.AncestryChanged:Wait()
end

You do:

while Character.Parent == nil do
	Character.AncestryChanged:Wait()
end

Did you see it?

~= :heavy_multiplication_x: == :heavy_check_mark:

1 Like