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

Attempt to index nil with 'InputBegan'?

Asked by 4 years ago
Edited 4 years ago

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

0
Did you define UIS? R_alatch 394 — 4y
0
If you defined UIS, then may you please add that so we know. Hoogidy_Boogidy 18 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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)
0
didn't work. Abacus300 7 — 4y
0
got the same problem as before Abacus300 7 — 4y
0
The code works for me. Are you running this code in a local script? It should be in a local script. wurldburd 86 — 4y
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. Abacus300 7 — 4y
View all comments (2 more)
0
UserInputService only works for the client in a local script. That's your problem.3 wurldburd 86 — 4y
0
Yeah, i forgot that. Abacus300 7 — 4y
Ad

Answer this question