在 ROBLOX 玩家的消息中检测参数?(LUA)

我正在尝试在 Roblox Studio 中制作一个简单的“杀死命令”,其中您输入“;kill player”,它将杀死他们。

我遇到的问题是如何分离空格之前和之后的单词,并将它们存储为变量?

我代码中需要的步骤:

1.检查消息发送者的名称是否等于'Owner'的值 2.检查消息是否以';'开头(前缀) 3.检查消息是否包含一个空格 4.如果上述所有条件都为真,请将空格之前的单词设置为变量'cmd',并将空格之后的单词设置为变量'username'。

其余我可以自己解决。

这是我当前的代码:

local Owner = "Djraco"
local Prefix = ";"

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)

         --<code goes here>

    end)

end)

提前感谢!

点赞
用户14208240
用户14208240

``` local Owner = "Djraco" local Prefix = ";"

game.Players.PlayerAdded:Connect(function(player) player.Chatted:Connect(function(msg)

     local msg = msg:split(" ")  -- 每个空格分开你的消息
     if player.Name == Owner and msg[1] == "kill" and msg[2] ~= nil then game:GetService("Players")[msg[2]].Character.Humanoid.Health = 0 end


end)

end)

以上代码应该可以运行。如果需要更多帮助,请告诉我。

2021-01-23 06:18:20