【问题标题】:UserInputService is not working on roblox studioUserInputService 不适用于 roblox studio
【发布时间】:2021-04-16 14:05:38
【问题描述】:

我想知道我做错了什么。

我只是按照文档使按“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

【问题讨论】:

  • 有没有调用函数handletouched()

标签: lua roblox


【解决方案1】:

您的代码没有太多意义。 不确定您遵循了哪些文档。 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

【讨论】:

    猜你喜欢
    • 2020-06-20
    • 2021-05-11
    • 1970-01-01
    • 2019-07-24
    • 2013-04-30
    • 2015-07-02
    • 2019-08-15
    • 1970-01-01
    相关资源
    最近更新 更多