Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RunService = game:GetService("RunService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local isServer = RunService:IsServer()
- local remotesFolder
- local bindablesFolder = Instance.new("Folder")
- bindablesFolder.Name = "Bindables"
- bindablesFolder.Parent = ReplicatedStorage
- if isServer then
- remotesFolder = Instance.new("Folder")
- remotesFolder.Name = "Remotes"
- remotesFolder.Parent = ReplicatedStorage
- else
- remotesFolder = ReplicatedStorage:WaitForChild("Remotes")
- end
- local NetworkUtil = {}
- local function findFirstChildOfNameAndClass(parent, name, class)
- for _, child in ipairs(parent:GetChildren()) do
- if child.Name == name and child:IsA(class) then
- return child
- end
- end
- end
- function NetworkUtil:GetRemoteEvent(name)
- local remote = findFirstChildOfNameAndClass(remotesFolder, name, "RemoteEvent")
- if not remote and isServer then
- remote = Instance.new("RemoteEvent")
- remote.Name = name
- remote.Parent = remotesFolder
- end
- return remote
- end
- function NetworkUtil:GetRemoteFunction(name)
- local remote = findFirstChildOfNameAndClass(remotesFolder, name, "RemoteFunction")
- if not remote and isServer then
- remote = Instance.new("RemoteFunction")
- remote.Name = name
- remote.Parent = remotesFolder
- end
- return remote
- end
- function NetworkUtil:GetBindableEvent(name)
- local bindable = findFirstChildOfNameAndClass(bindablesFolder, name, "BindableEvent")
- if not bindable then
- bindable = Instance.new("BindableEvent")
- bindable.Name = name
- bindable.Parent = bindablesFolder
- end
- return bindable
- end
- function NetworkUtil:GetBindableFunction(name)
- local bindable = findFirstChildOfNameAndClass(bindablesFolder, name, "BindableFunction")
- if not bindable then
- bindable = Instance.new("BindableFunction")
- bindable.Name = name
- bindable.Parent = bindablesFolder
- end
- return bindable
- end
- return NetworkUtil
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement