【问题标题】:Roblox chat Commands inside a localscript?本地脚本中的 Roblox 聊天命令?
【发布时间】:2021-11-18 04:29:50
【问题描述】:

如何在本地脚本中创建 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)

【问题讨论】:

  • LocalScripts 中所做的更改只会影响您的客户端,而不是整个世界。为什么不直接将此代码移到服务器端脚本中?

标签: lua roblox


【解决方案1】:

它可以在 LocalScript 中运行,但我建议您将它放在服务器脚本中。该代码适用于所有人,因为您没有使用 LocalPlayer。我还建议让 admin 表使用 UserId 而不是 Name,因为有人可以更改他们的名字并使脚本无法工作。而且我还建议使用 if Admins[plr.UserId] then 而不是遍历 Admin 表。与让目标玩家改变速度相同。

【讨论】:

    【解决方案2】:

    可以在 LocalScript 中执行此操作,但当然不建议这样做。任何人都可以利用脚本中的功能。将其移至服务器端脚本并使用 RemoteEvents 是最好的主意。

    【讨论】:

      猜你喜欢
      • 2013-08-06
      • 2015-05-17
      • 1970-01-01
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      相关资源
      最近更新 更多