Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Author(s): MohhayScripts
- --!strict
- --// Services
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- --// Modules
- local Packages = ReplicatedStorage.Packages
- local Janitor = require(Packages.Janitor)
- local Promise = require(Packages.Promise)
- local Logger = require(ReplicatedStorage.Resources.Client.Logger).attach(script.Name)
- --// Variables
- local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
- local InternalEvent = RemotesFolder:WaitForChild("921A096C-7EB1-496F-8ABB-43F91FFE6933") :: RemoteEvent
- local remoteIdentifiers
- --// Init
- InternalEvent.OnClientEvent:Connect(function(newValue)
- remoteIdentifiers = newValue
- end)
- InternalEvent:FireServer()
- if not remoteIdentifiers then
- repeat task.wait()
- until remoteIdentifiers
- end
- local Remote = {}
- Remote.__index = Remote
- function Remote.get(remoteName: string)
- local self = setmetatable({}, Remote)
- self._remoteName = remoteName
- if not remoteIdentifiers[remoteName] then
- Logger.error(remoteName.." does not have a registered identifier! This needs to be investigated. Current remote identifiers: "..remoteIdentifiers, "🌐")
- return
- end
- self._remote = RemotesFolder:WaitForChild(remoteIdentifiers[remoteName])
- self._janitor = Janitor.new()
- function self.OnClientEvent(func: (...any) -> any): RBXScriptConnection
- return self._janitor:Add(self._remote.OnClientEvent:Connect(function(...)
- func(...)
- end))
- end
- function self.OnClientOnce(func: (...any) -> any): ()
- local connection
- connection = self._remote.OnClientEvent:Connect(function(...)
- connection:Disconnect()
- func(...)
- end)
- end
- Logger.info("Imported remote "..remoteName.." successfuly!", "🌐")
- return self
- end
- function Remote:FireServer(...: any): ()
- if self._remote.ClassName == "RemoteEvent" then
- self._remote:FireServer(...)
- elseif self._remote.ClassName == "RemoteFunction" then
- Logger.error(`RemoteFunction does not have a function called ":FireServer"! Did you mean to run ":InvokeServer()"?`, "🌐")
- else
- Logger.error(`{self._remoteName} is not a RemoteEvent nor a RemoteFunction and you tried to run ":FireServer()"! This needs to be investigated throughougly! Please take a screenshot of this and send it to one of our developers in our social communications server!`, "🌐")
- end
- end
- function Remote:InvokeServer(...: any): any
- if self._remote.ClassName == "RemoteFunction" then
- return self._remote:InvokeServer(...)
- elseif self._remote.ClassName == "RemoteEvent" then
- Logger.error(`RemoteEvent does not have a function called ":InvokeServer()"! Did you mean to run ":FireServer()"?`, "🌐")
- return
- else
- Logger.error(`{self._remoteName} is not a RemoteEvent nor a RemoteFunction and you tried to run ":InvokeServer()"! This needs to be investigated throughougly! Please take a screenshot of this and send it to one of our developers in our social communications server!`, "🌐")
- return
- end
- end
- function Remote:InvokeServerAsync(arguments: any): typeof(Promise.prototype) | any
- if self._remote.ClassName == "RemoteFunction" then
- return Promise.new(function(resolve)
- resolve(self._remote:InvokeServer(table.unpack(arguments)))
- end) :: typeof(Promise.prototype)
- elseif self._remote.ClassName == "RemoteEvent" then
- Logger.error(`{self._remote.ClassName} does not have a function called ":InvokeServer()"! Did you mean to run ":FireServer()"?`, "🌐")
- return
- else
- Logger.error(`{self._remoteName} is not a RemoteEvent nor a RemoteFunction and you tried to run ":InvokeServerAsync()"! This needs to be investigated throughougly! Please take a screenshot of this and send it to one of our developers in our social communications server!`, "🌐")
- return
- end
- end
- function Remote:Destroy(): ()
- self._janitor:Destroy()
- table.clear(self)
- end
- return Remote
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement