首页 > 解决方案 > UserInputService 不适用于 roblox studio

问题描述

我想知道我做错了什么。

我只是按照文档使按“E”键在控制台上显示“打印”并说“按”但它没有用,我做错了什么?

-- 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

标签: luaroblox

解决方案


您的代码没有太大意义。不确定您遵循了哪些文档。Roblox 文档及其示例非常清楚地说明了该做什么。

你定义了一个handletouched永远不会被调用的函数。

在该函数中,您将事件对象与数字进行比较,这当然永远不会相等。

请阅读https://developer.roblox.com/en-us/api-reference/event/UserInputService/InputBegan

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

你有一个被游戏触发的事件,你必须提供一个事件处理函数。您实现该功能,然后将其连接到事件。因此,无论何时触发事件,都会调用此函数。

在实现自己的代码之前,您应该更仔细地阅读并首先尝试理解文档中给出的示例。

确保你明白这一点:

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


推荐阅读