如何在本地脚本中使用 Roblox 聊天命令?

如何在本地脚本中使用 Roblox 聊天命令?是否可能?如果可以或不行,请让我知道并将下面的代码复制到您的本地脚本中。

local Admins = {""}
local Prefix = "/"

game.Players.PlayerAdded:Connect(function(plr)
for _,v in pairs(Admins) do
    if plr.Name == v then
        plr.Chatted:Connect(function(msg)
            local loweredString = string.lower(msg)
            local args = string.split(loweredString," ")
            if args[1] == Prefix.."walkspeed" then
                for _,player in pairs(game:GetService("Players"):GetPlayers()) do
                    if string.sub(string.lower(player.Name), 1, string.len(args[2])) ==
string.lower(args[2]) then
                        player.Character.Humanoid.WalkSpeed = args[3]
                    end
                end
            end
        end)
    end
end
end)

原文链接 https://stackoverflow.com/questions/69322624

点赞
stackoverflow用户11621983
stackoverflow用户11621983

可以在 LocalScript 中实现此功能,但这绝对不是建议的做法。任何人都可以利用脚本中的函数。将其移动到服务器端脚本并使用 RemoteEvents 是最好的想法。

2021-09-28 21:04:51
stackoverflow用户16938675
stackoverflow用户16938675

它可以在 LocalScript 中工作,但我建议将其放在服务器脚本中。代码将适用于所有人,因为您没有使用 LocalPlayer。我还建议将管理员表使用 UserId 而不是 Name,因为有人可能会更改他们的名字并使脚本无法工作。我还建议使用 if Admins[plr.UserId] then 而不是迭代管理员表。与获取目标玩家以更改速度一样。

2021-09-29 05:56:18