UserInputService 在 roblox studio 上无法工作

我想知道我做错了什么。

我刚刚按照文档的说明让按下“E”键在控制台上显示“print”并说“Pressed”,但它没有起作用,我做错了什么?

-- 输入
local UserInputService = game:GetService("UserInputService")
-- 输入

-- 角色处理
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
点赞
用户2858170
用户2858170

你的代码意义不太明确。

我不确定你按照哪份文档编写。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

2021-01-12 08:17:24