如何使MainModule脚本仅在组场所的所有者或场所的所有者拥有某个项目时才运行?
代码行是什么?
答案 0 :(得分:0)
只要模块的名称是“ 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