Global is a simple server to client replication system managed internally by Value Objects.
This module was created mainly to replicate player data and guarantee that the data is always synced with the server and received properly from the server.
This module is basically a “Global Table” that is always synced and guaranteed to be replicated to the client. Sharing data from the server constantly using remote events could be a pain for some of you.
– Grab it here –
Roblox Library
The examples down below are really not what it’s for but it’s the logic behind it
Server Example:
local Global = require(path.to.module)
Global.Data.TimeRemaining = 60
task.spawn(function()
while task.wait(1) do
Global.Data.TimeRemaining = math.clamp(Global.Data.TimeRemaining - 1, 0, math.huge)
end
end)
-- Anything inside the .Data table will be replicated to the client
-- the roblox remote-events limitations are however still the same
Client Example:
local Global = require(path.to.module)
local RunService = game:GetService("RunService")
Global.Wait() -- Call this to guarantee that the client Global.Data is never nil and is received by the client, this usually happens when the client first loads.
RunService.Heartbeat:Connect(function()
if not Global.Data.TimeRemaining then -- In very rare cases the value might not be available yet so we wait for it
return
end
print(Global.Data.TimeRemaining) -- We retrieve the TimeRemaining data from the Global Table
end)
-- Now the TimeRemaining is synced and guaranteed to be received by the client