Suphi's RemoteFunction Module

Suphi's RemoteFunction Module

Download | Video Tutorial | Discord Server


Support My Work

If you liked my work and want to donate to me you can do so here


SourceCode

You can get the sourcecode to this module here

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.


Documentation

CONSTRUCTOR

new(name: string, event: function?)
"Returns previously created RemoteFunction else a new RemoteFunction"

PROPERTIES

Event  function?  nil
"Function that will be called when fired"

METHODS

Fire(arguments...: tuple)  tuple
"Fires a event and waits for a response if there was no response it will timeout in 10 seconds and return nil"
Destroy()  nil
"Destroy the RemoteFunction"

Examples

EXAMPLE 1

-- SERVER
local RemoteFunctionModule = require(15869447845)

-- Find or create a RemoteFunction object
local remoteFunction = RemoteFunctionModule.new("Name")

-- Wait for a player to join
local player = game.Players.PlayerAdded:Wait()

-- Fire a event to the client and wait for a response
local response = remoteFunction:Fire(player, "Hello")
print("Client responded:", response)
-- CLIENT
local RemoteFunctionModule = require(15869447845)

-- Find or create a RemoteFunction object
local remoteFunction = RemoteFunctionModule.new("Name")

-- Connect a function to Event
remoteFunction.Event = function(message)
    print("Server said:" message)
    return "World"
end

EXAMPLE 2

-- SERVER
local RemoteFunctionModule = require(15869447845)
-- its also possible to connect a function to Event directly in the new function
RemoteFunctionModule.new("Name", function(player, message)
    print("Client", player.Name, "said:", message)
    return "World"
end)
-- CLIENT
local RemoteFunctionModule = require(15869447845)
local remoteFunction = RemoteFunctionModule.new("Name")
local response = remoteFunction:Fire("Hello")
print("Server responded:", response)

EXAMPLE 3

-- SERVER
local RemoteFunctionModule = require(15869447845)
local remoteFunction = RemoteFunctionModule.new("Name", function(player, ...)
    print("Server Received:", ...)
    local random = math.random(1, 100)
    print("Server Sent:", random)
    return random
end)

local player = game.Players.PlayerAdded:Wait()

for index = 1, 4 do
    print("Server Loop Sent:", index)
    warn("Server Loop Received:", remoteFunction:Fire(player, index))
    task.wait(8)
end
-- CLIENT
local RemoteFunctionModule = require(15869447845)
local remoteFunction = RemoteFunctionModule.new("Name", function(...)
    print("Client Received:", ...)
    local random = math.random(1, 100)
    print("Client Sent:", random)
    return random
end)

task.wait(4)

for index = 1, 4 do
    print("Client Loop Sent:", index)
    warn("Client Loop Received:", remoteFunction:Fire(index))
    task.wait(8)
end

EXAMPLE 4

-- SERVER
local RemoteFunctionModule = require(15869447845)
local remoteFunction = RemoteFunctionModule.new("Name")
local player = game.Players.PlayerAdded:Wait()
local response = remoteFunction:Fire(player, "Hello")
if response == nil then
    warn("RemoteFunction timed out")
else
    print("Client responded:", response)
end
-- CLIENT
local RemoteFunctionModule = require(15869447845)
local remoteFunction = RemoteFunctionModule.new("Name", function(message)
    return nil -- returning nil will make the server timeout after 10 seconds 
end)

Other Projects

Infinite Terrain
Suphi’s DataStore Module
Infinite Scripter
Mesh Editor
Toggle Decomposition Geometry
Tag Explorer
Suphi’s RemoteFunction Module

17 Likes