【发布时间】:2019-02-05 20:12:32
【问题描述】:
如何才能使 MainModule 脚本仅在群组场所的所有者或场所的所有者拥有某个项目时才运行?
代码行是什么?
【问题讨论】:
标签: roblox
如何才能使 MainModule 脚本仅在群组场所的所有者或场所的所有者拥有某个项目时才运行?
代码行是什么?
【问题讨论】:
标签: roblox
只要模块的名称是“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
【讨论】: