2024-01-05 12:14:38 +00:00
|
|
|
--!strict
|
|
|
|
local RunService = game:GetService("RunService")
|
|
|
|
local Type = require(script.Parent.Type)
|
|
|
|
|
2024-05-02 12:11:27 +00:00
|
|
|
local function createInstance(parent: Instance, name: string, class: string)
|
|
|
|
if not parent:FindFirstChild(name) then
|
2024-05-02 18:51:34 +00:00
|
|
|
local newInstance = Instance.new(class)
|
2024-05-02 12:11:27 +00:00
|
|
|
newInstance.Name = name
|
|
|
|
newInstance.Parent = parent
|
2024-01-05 12:14:38 +00:00
|
|
|
end
|
2024-05-02 12:11:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function waitForChildren(parent: Instance, childrenNames: {string})
|
2024-05-02 18:51:34 +00:00
|
|
|
for _, name in ipairs(childrenNames) do
|
2024-05-02 12:11:27 +00:00
|
|
|
task.spawn(function()
|
|
|
|
repeat
|
|
|
|
task.wait()
|
|
|
|
until parent:FindFirstChild(name)
|
|
|
|
end)
|
2024-01-05 12:14:38 +00:00
|
|
|
end
|
2024-05-02 12:11:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if RunService:IsServer() then
|
|
|
|
createInstance(script, "Reliable", "RemoteEvent")
|
|
|
|
createInstance(script, "Unreliable", "UnreliableRemoteEvent")
|
|
|
|
createInstance(script, "Request", "RemoteEvent")
|
|
|
|
else
|
|
|
|
waitForChildren(script, {"Reliable", "Unreliable", "Request"})
|
2024-01-05 12:14:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
2024-01-09 06:26:47 +00:00
|
|
|
Reliable = script.Reliable,
|
|
|
|
Unreliable = script.Unreliable,
|
2024-01-05 12:14:38 +00:00
|
|
|
Request = script.Request
|
2024-05-02 12:11:27 +00:00
|
|
|
} :: Type.Event
|