Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Author(s): MohhayScripts
- --!strict
- --// Services
- local HttpService = game:GetService("HttpService")
- local Players = game:GetService("Players")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- --// Modules
- local Logger = require(ReplicatedStorage.Resources.Client.Logger).attach(script.Name)
- --// Variables
- local remoteIdentifiers = {}
- local receivedIdentifiers = {}
- local RemotesFolder = ReplicatedStorage:WaitForChild("Remotes")
- local InternalEvent = RemotesFolder:WaitForChild("921A096C-7EB1-496F-8ABB-43F91FFE6933") :: RemoteEvent
- local function generateUniqueID(): string
- local id = HttpService:GenerateGUID(false)
- return if table.find(remoteIdentifiers, id) then generateUniqueID() else id
- end
- --// Init
- setmetatable(remoteIdentifiers, {
- __newindex = function(t, index, value)
- rawset(t, index, value)
- for _, Player in Players:GetPlayers() do
- InternalEvent:FireClient(Player, t)
- end
- end
- })
- InternalEvent.OnServerEvent:Connect(function(Player)
- if receivedIdentifiers[Player] then
- Player:Kick("Stop exploiting...")
- return
- end
- receivedIdentifiers[Player] = true
- InternalEvent:FireClient(Player, remoteIdentifiers)
- end)
- local Remote = {}
- Remote.__index = Remote
- function Remote.new(remoteName: string, remoteType: ("RemoteEvent"?) | ("RemoteFunction"?))
- local self = setmetatable({}, Remote)
- self._remoteName = remoteName
- if remoteIdentifiers[self._remoteName] then
- Logger.info(`{self._remoteName} has already been registered once before and you are trying to get it again. Please do not use the same remote event across different modules, if you are, you are using a bad coding structure.`, "🌐")
- self._remote = RemotesFolder:WaitForChild(remoteIdentifiers[self._remoteName])
- else
- remoteIdentifiers[self._remoteName] = generateUniqueID()
- self._remote = Instance.new(remoteType)
- self._remote.Name = remoteIdentifiers[self._remoteName]
- self._remote.Parent = RemotesFolder
- end
- function self.OnServerEvent(func: (...any) -> any): RBXScriptConnection
- return self._remote.OnServerEvent:Connect(function(...)
- func(...)
- end)
- end
- function self.OnServerOnce(func: (...any) -> any): ()
- local connection
- connection = self._remote.OnServerEvent:Connect(function(...)
- connection:Disconnect()
- func(...)
- end)
- end
- function self.OnServerInvoke(callback: (...any) -> any): ()
- self._remote.OnServerInvoke = callback
- end
- Logger.info("Created remote "..remoteName.." successfuly!", "🌐")
- return self
- end
- function Remote:FireClient(player: Player, ...: any): ()
- if self._remote.ClassName == "RemoteEvent" then
- self._remote:FireClient(player, ...)
- elseif self._remote.ClassName == "RemoteFunction" then
- Logger.error(`RemoteFunction does not have a function called ":FireClient()"! Did you perhaps put in the wrong remoteType when creating the Remote?`, "🌐")
- else
- Logger.error(`{self._remoteName} is not a RemoteEvent nor a RemoteFunction. This needs to be investigated throughougly!`, "🌐")
- end
- end
- function Remote:FireAllClients(...: any): ()
- if self._remote.ClassName == "RemoteEvent" then
- self._remote:FireAllClients(...)
- elseif self._remote.ClassName == "RemoteFunction" then
- Logger.error(`RemoteFunction does not have a function called ":FireAllClients()"! Did you perhaps put in the wrong remoteType when creating the Remote?`, "🌐")
- else
- Logger.error(`{self._remoteName} is not a RemoteEvent nor a RemoteFunction. This needs to be investigated throughougly!`, "🌐")
- end
- end
- function Remote:FireMultipleClients(clients: {Player}, ...: any): ()
- if self._remote.ClassName == "RemoteEvent" then
- for _, client in clients do
- self._remote:FireClient(client, ...)
- end
- elseif self._remote.ClassName == "RemoteFunction" then
- Logger.error(`RemoteFunction does not have a function called ":FireMultipleClients()"! Did you perhaps put in the wrong remoteType when creating the Remote?`, "🌐")
- else
- Logger.error(`{self._remoteName} is not a RemoteEvent nor a RemoteFunction. This needs to be investigated throughougly!`, "🌐")
- end
- end
- function Remote:FireAllClientsExcept(clients: {Player}, ...: any): ()
- if self._remote.ClassName == "RemoteEvent" then
- for _, client in Players:GetPlayers() do
- if table.find(clients, client) then
- continue
- end
- self._remote:FireClient(client, ...)
- end
- elseif self._remote.ClassName == "RemoteFunction" then
- Logger.error(`RemoteEvent does not have a function called ":FireAllClientsExcept()"! Did you perhaps put in the wrong remoteType when creating the Remote?`, "🌐")
- else
- Logger.error(`{self._remoteName} is not a RemoteEvent nor a RemoteFunction. This needs to be investigated throughougly!`, "🌐")
- end
- end
- function Remote:FireAllClientsInRange(position: Vector3, radius: number, ...: any): ()
- if self._remote.ClassName == "RemoteEvent" then
- for _, client in Players:GetPlayers() do
- if client.Character == nil or client.Character:FindFirstChild("HumanoidRootPart") == nil or (client.Character.HumanoidRootPart.Position - position).Magnitude > radius then
- continue
- end
- self._remote:FireClient(client, ...)
- end
- elseif self._remote.ClassName == "RemoteFunction" then
- Logger.error(`RemoteEvent does not have a function called ":FireAllClientsInRange()"! Did you perhaps put in the wrong remoteType when creating the Remote?`, "🌐")
- else
- Logger.error(`{self._remoteName} is not a RemoteEvent nor a RemoteFunction. This needs to be investigated throughougly!`, "🌐")
- end
- end
- function Remote:FireAllClientsInRangeExcept(clients: {Player}, position: Vector3, radius: number, ...: any): ()
- if self._remote.ClassName == "RemoteEvent" then
- for _, client in Players:GetPlayers() do
- if client.Character == nil or client.Character:FindFirstChild("HumanoidRootPart") == nil or (client.Character.HumanoidRootPart.Position - position).Magnitude > radius or table.find(clients, client) then
- continue
- end
- self._remote:FireClient(client, ...)
- end
- elseif self._remote.ClassName == "RemoteFunction" then
- Logger.error(`RemoteEvent does not have a function called ":FireAllClientsInRangeExcept()"! Did you perhaps put in the wrong remoteType when creating the Remote?`, "🌐")
- else
- Logger.error(`{self._remoteName} is not a RemoteEvent nor a RemoteFunction. This needs to be investigated throughougly!`, "🌐")
- end
- end
- return Remote
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement