Ghi chú phát hành
Học
Lớp công cụ
PluginConnectionService
Không Thể Tạo
Dịch Vụ
Không Sao Chép

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.


Tóm Tắt
Thành viên kế thừa
Mẫu mã
Kết nối PluginConnection echo Plugin
local Service = game:GetService("PluginConnectionService")
local TestType = Enum.PluginConnectionTargetType.Test
local EditType = Enum.PluginConnectionTargetType.Edit
local function MakeConnection(Connection: PluginConnection, Side: string)
assert(Connection.Connected)
local Count = 0
local Binding = Connection:BindToMessage(function(Msg: string)
print(Msg)
task.wait(1)
if Connection.Connected then
Connection:SendMessage(`Xin chào từ {Side} iteration {Count}`)
end
Count += 1
end)
plugin.Unloading:Connect(function()
Binding:Disconnect()
end)
Connection:GetPropertyChangedSignal("Connected"):Once(function()
assert(not Connection.Connected)
print("Ngắt kết nối", Connection.TargetId)
end)
end
if Service:CanHaveConnectionType(TestType) then
for _, ExistingConnection in Service:GetPluginConnectionsOfType(TestType) do
MakeConnection(ExistingConnection, "Chỉnh sửa")
end
Service.Connected:Connect(function(NewConnection)
if NewConnection.Type == TestType then
MakeConnection(NewConnection, "Chỉnh sửa")
end
end)
elseif Service:CanHaveConnectionType(EditType) then
local Connections = Service:GetPluginConnectionsOfType(EditType)
assert(#Connections <= 1)
local Connection: PluginConnection? = nil
if #Connections == 1 then
Connection = Connections[1]
else
while true do
local NewConnection = Service.Connected:Wait()
if NewConnection.Type == EditType then
Connection = NewConnection
break
end
end
end
assert(Connection)
assert(Connection.Connected)
MakeConnection(Connection, if game:GetService("RunService"):IsServer() then "Máy chủ" else "Khách")
Connection:SendMessage("Xin chào Chỉnh sửa!")
end

Tài Liệu Tham Khảo API
Phương Pháp
CanHaveConnectionType
Bảo Mật Plugin
PluginConnectionService:CanHaveConnectionType(type:Enum.PluginConnectionTargetType):boolean
Lợi Nhuận

GetPluginConnectionsOfType
Bảo Mật Plugin
PluginConnectionService:GetPluginConnectionsOfType(type:Enum.PluginConnectionTargetType):{PluginConnection}
Lợi Nhuận

Sự Kiện
Connected
Bảo Mật Plugin
PluginConnectionService.Connected(conn:PluginConnection):RBXScriptSignal
Tham Số

©2026 Roblox Corporation. Roblox, logo Roblox và Powering Imagination là các nhãn hiệu đã đăng ký và chưa đăng ký của chúng tôi tại Hoa Kỳ và các quốc gia khác.