简体   繁体   中英

UserInputService is not working on roblox studio

I would like to know what I am doing wrong.

I just followed the documentation to make pressing the "E" key show a "print" on the console and say "Pressed" but it hasn't worked, what am I doing wrong?

-- input
local UserInputService = game:GetService("UserInputService")
--input

-- rolehandle
local function handletouched()
    handle.Touched:Connect(function(fas)
        wait(3)
        role.Value = "-"
        if game:GetService("UserInputService").InputBegan == Enum.KeyCode.E then
            print("pressed")
        end
    end)
end

Your code doesn't make too much sense. Not sure which documentation you followed. The Roblox documentation and its examples are pretty clear about what to do.

You define a function handletouched that is never called.

In that function you compare an event object vs a number, which of course are never equal.

Please read https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputBegan

and

https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched

You have an event that is fired by the game and you have to provide an event handler function. You implement that function and then connect it to the event. So whenever the event is fired, this function will be called.

You should read more carefully and first try to understand the examples given in the documentation befor you implement your own code.

Make sure you understand this:

https://developer.roblox.com/en-us/articles/events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM