ROBLOX Studio:当您单击时,如何为部分编写脚本以分配您至团队?

ROBLOX Studio:当您单击时,如何为部分编写脚本以分配您至团队?

点赞
用户2858170
用户2858170

阅读:

https://developer.roblox.com/en-us/api-reference/event/ClickDetector/MouseClick

为该部件实现一个 MouseClick 事件监听器。然后使用 playerWhoClicked 参数来确定哪个玩家点击了。在该监听器中,将 Team 实例分配给该玩家的 Team 属性。

阅读:

https://developer.roblox.com/en-us/api-reference/class/Team

https://developer.roblox.com/en-us/api-reference/property/Player/Team

2021-04-19 06:21:08
用户15107943
用户15107943

首先,你需要在资源管理器的团队服务中插入一个团队对象。如果它没有显示出来,点击“Model” > “Services” > “Teams”,并点击“Insert”按钮:Go To Model And Services

然后,在团队服务中插入一个团队对象,并按需自定义。![Teams Service](https://i.stack.imgur.com/qXd7B.png)

之后,在场景中创建一个部分,并在其中放置一个脚本和一个点击检测器。[![PartScriptClickDetector](https://i.stack.imgur.com/XzTJ0.png)]( https://i.stack.imgur.com/XzTJ0.png)

然后,将以下脚本放置在其中,并进行适合游戏的更改:

local TeamsService = game:GetService('Teams')
-- 将你的团队名称写入等待的子项目
local Team = TeamsService:WaitForChild('Noobs')
local ClickDetector = script.Parent:WaitForChild('ClickDetector')

local function AssignTeam(Player)
    Player.Team = Team
end

ClickDetector.MouseClick:Connect(AssignTeam)

此外,点击检测器也适用于移动设备。

2021-04-19 10:48:12