:StopListening
Stops listening for updates for a specific realKey. This informs the server to stop sending updates for this key to this client and cleans up all local resources (cache entry and signals) associated with it.
It's a crucial practice to call this when a piece of UI is destroyed or a system no longer needs the data to prevent memory leaks and unnecessary network traffic.
DataReplicator:StopListening(realKey: string)
realKey: stringThe original data key.
local scoreboardFrame = script.Parent
local TEAM_SCORE_KEY = "Public_TeamScore_Blue"
-- Start listening when the scoreboard is created.
local teamScoreSignal = DataReplicator:Listen(TEAM_SCORE_KEY)
local connection = teamScoreSignal:Connect(function(score)
-- ... update UI ...
end)
-- When the scoreboard is destroyed, stop listening to free up resources.
scoreboardFrame.Destroying:Connect(function()
connection:Disconnect()
DataReplicator:StopListening(TEAM_SCORE_KEY)
print("Stopped listening to team score updates.")
end)Last updated