UserInputService.InputBegan not working?

Hello, I’ve been trying to make an ability in my game and it didn’t work, I then copied some code from one of my other games and it still didn’t work for some reason (it works in the other game), so I would like to know why this isn’t working.
Here’s the code:

local plr = game.Players.LocalPlayer
local char = plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local rootpart = char:WaitForChild("HumanoidRootPart")
local rs = game:GetService("RunService")
local replicated = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local gameplayUI = plr.PlayerGui:WaitForChild("GameplayUI")
gameplayUI.Enabled = true
local rayIgnore = {char}

	if g then return end
	if i == Enum.KeyCode.C then
		if hum:GetState() == Enum.HumanoidStateType.Freefall or hum:GetState() == Enum.HumanoidStateType.Jumping then
			local ray =
			ray.FilterDescendantsInstances = rayIgnore
			local hit = workspace:Raycast(rootpart.Position,(-rootpart.CFrame.LookVector*10),ray)
			if hit then
				print("found part")
				rootpart.Velocity = (rootpart.CFrame.LookVector*57)
				print("part not found")

You did not put i.KeyCode

Change the line to this:

if i.KeyCode == Enum.KeyCode.C then

It is required to detect keyboard and controller input because “i” can detect way more than just that. KeyCode specifies it is from either a keyboard or controller.


How did I miss that… Thank you, you saved me from spending another 5 hours on this.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.