【问题标题】:Roblox | How to make it so a MainModule script only runs of the owner of the group place or the owner of the place, owns a certain item?机器人 |如何使 MainModule 脚本仅运行组场所的所有者或场所的所有者,拥有某个项目?
【发布时间】:2019-02-05 20:12:32
【问题描述】:

如何才能使 MainModule 脚本仅在群组场所的所有者或场所的所有者拥有某个项目时才运行?

代码行是什么?

【问题讨论】:

    标签: roblox


    【解决方案1】:

    只要模块的名称是“MainModule”,就可以在除客户端之外的任何环境中(通过 AssetID)被要求。

    代码:

    local players = game:GetService("Players")
    local moduleToRequire = require(2368285483) -- set to your module's ID
    
    function playerAdded(player)
        if game.CreatorType == Enum.CreatorType.User then
            if player == game.CreatorId then
                moduleToRequire() -- assuming your module returns a function; format to your module.
            end
        else -- has to be Enum.CreatorType.Group
            if player:IsInGroup(game.CreatorId) and player:GetRankInGroup(game.CreatorId) == 255 then
                moduleToRequire()
            end
        end
    end
    
    players.PlayerAdded:Connect(playerAdded)
    

    当需要 ModuleScript 时,它返回的内容之外的所有内容都会在需要它之前运行一次。

    参考资料:

    https://www.robloxdev.com/api-reference/function/Player/GetRankInGroup

    https://www.robloxdev.com/api-reference/datatype/Enums

    https://www.robloxdev.com/api-reference/function/Player/IsInGroup

    https://www.robloxdev.com/api-reference/property/DataModel/CreatorId

    【讨论】:

      猜你喜欢
      • 2021-02-13
      • 1970-01-01
      • 2015-01-16
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多