Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to index nil with 'InputBegan'?

So, I am trying to code some script that i forgot i had a long time ago and I keep on getting the error: "Workspace.InfOHac.fur:1486: attempt to index nil with 'InputBegan'". and it is annoying me a lot, my code is

UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(io, gpe, input, gameProcessed)
	if(gpe or Attack)then return end
	if(io.KeyCode==Enum.KeyCode.Q)then
		Personality=Personality-1
		if(Personality<1)then Personality=5 end
	elseif(io.KeyCode==Enum.KeyCode.E)then
		Personality=Personality+1
		if(Personality>5)then Personality=1 end	
	elseif(io.KeyCode==Enum.KeyCode.Semicolon)then
               ManualMode=true
	elseif(io.KeyCode==Enum.KeyCode.R)then
		ChangeStance'Sit'
	elseif(io.KeyCode==Enum.KeyCode.F)then
		ChangeStance'Auto'
	end
end)

Can someone help me because it is getting me really annoyed and I don't know how to fix it.

Sorry if it is unreadable

Edit: Yes i did define UserInputService

2 comments

0

Did you define UIS?

0

If you defined UIS, then may you please add that so we know.

1 answer

✓ Accepted answer

Try using this bit of code for detecting input instead:

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, busy)
	if busy then return end
	
	if input.KeyCode == Enum.KeyCode.E then
		print("E")
	elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("Left Click")
	end
end)

6 comments

0

didn't work.

0

got the same problem as before

0

The code works for me. Are you running this code in a local script? It should be in a local script.

0

Well, the script that i am making is going to be server sided and it was originally a normal script when i found it again.

0

UserInputService only works for the client in a local script. That's your problem.3

0

Yeah, i forgot that.

This discussion is preserved as it was. New answers, comments, and votes are closed.