Remote events for scoreboard text help

Hi, I have a system for setting scoreboards to what I type in a screengui for a live game show, but I don’t know how to make it update for the other players using remote events.
The script I currently use is this:

local box = script.Parent -- the TextBox
local secondBox = game.Workspace.Podium1.money.SurfaceGui.TextBox --- the second one where ever it is
local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEventTest")

local function onTyped() -- callback
	    secondBox.Text = box.Text   
	  
end

box:GetPropertyChangedSignal("Text"):Connect(onTyped) -- pass callback to listener

and I am trying to use this guide https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events to use the remote events, however, I am confused on which form of remote event to do and apply it to my script. I believe I need server to all clients, but I’m not sure.

Before I start, I suggest changing the TextBox in the SurfaceGui to a TextLabel to prevent other users from altering the Text on their side. I made this change in the scripts below.

In this case, it’d be preferable to use a Remote Event.
You will want to edit the TextLabel (in workspace) from the Script, so I removed that variable for this LocalScript:

local Box = script.Parent
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEventTest")

local function onTyped() -- Callback
    RemoveEvent:FireServer(Box.Text) -- Send the Text property of Box to the server
end

box:GetPropertyChangedSignal("Text"):Connect(onTyped) -- Pass Callback to Listener

In the Server Script, we will retrieve what was sent from the Client and set the Text of the TextLabel:

local SecondBox = game.Workspace.Podium1.money.SurfaceGui.TextLabel -- Used to be a TextBox, now a TextLabel
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEventTest")

RemoteEvent.OnServerEvent:Connect(function(Player, Text)
    if Player.Name == 'putYourNameHere' then -- Set putYourNameHere to your name, this is for security to make sure other users can't change the scoreboard.
        SecondBox.Text = Text -- Sets the Text of SecondBox on the server so that all users will see the change
    end
end)
2 Likes

Also I think ROBLOX wants devs to always filter text that gets sent to client, even if it’s by the owner. Sadly which adds a lot more complexity to the proccess. Here’s a page on Text Filtering: https://developer.roblox.com/en-us/articles/Text-and-Chat-Filtering

Edit: I see that ROBLOX says that Text Filtering should be used when the developer does not have control over the content. So even though it wouldn’t be bad to include it, If you are in control it looks like it’s okay.

1 Like

Thanks, this worked, although you made a couple typos in the code.

Sorry about that, I typed it all in the DevForum and rushed a bit.

1 Like