:Listen
Starts listening for real-time data updates from the server for a specific realKey. This is the primary way to create reactive UI and game systems.
This function registers the client with the server for the given key (subject to authorization) and returns a custom Signal object. You can then connect a function to the .Event of this signal to be notified whenever the data is created, updated, or deleted.
DataReplicator:Listen(realKey: string)
realKey: stringThe original data key you want to listen to.
Signal - A custom Signal object. Connect to its .Event property to receive updates.
The event fires with the new data when it's updated.
The event fires with nil when the data is deleted on the server.
If data already exists when
:Listen()is first called, the event will fire once immediately with the current data.
local teamScoreLabel = script.Parent.TeamScoreLabel
local TEAM_SCORE_KEY = "Public_TeamScore_Blue"
-- Start listening for the blue team's score.
local teamScoreSignal = DataReplicator:Listen(TEAM_SCORE_KEY)
-- Connect a function to handle updates.
teamScoreSignal:Connect(function(newScore)
if newScore then
-- Update the UI with the new score.
teamScoreLabel.Text = `Blue Team: {newScore}`
else
-- The data was deleted, so we can hide or reset the UI.
teamScoreLabel.Text = "Blue Team: --"
end
end)Last updated