Having trouble understanding pushing textbox input from client to server

I’m making a simple thing where a user inputs an asset ID into a textbox on a surfacegui and upon input that asset’s thumbnail shows on another surfacegui. This works, but only locally to the player, because it’s a localscript. I’m failing to understand how to push it so that the image gets updated for everyone. I get the sense that this is done through remote events/functions(?) but I haven’t been able to comprehend how to set that up properly, despite reading up on it. Looking for an easier to comprehend explanation on how to get this done.

Not sure if this is important but the textbox input is located in startergui and the updating image surface is in workspace.

If anymore context is needed just ask.

1 Like

send textbox input from client to server using remote event, server gets the thumbnail and applies it to the surface
Remote Functions and Events (roblox.com)

1 Like

I tried going through this and running through the example but I wasn’t really able to grasp what was going on or why/how it works.

1 Like

Local

local REvent = game.ReplicatedStorage:WaitForChild("RemoteEventName")
REvent:FireServer(textbox.Text) -- fire server event from client passing textbox text

Server

local REvent = Instance.new("RemoteEvent")
REvent.Name = "RemoteEventName"
REvent.Parent = game.ReplicatedStorage
REvent.OnServerEvent:Connect(function(Player, Text) -- First param is the player that fired the event
	workspace.Blah.Image = GetImageUrl(Text)
end)
2 Likes

RemoteEvents are basically 1 way transportation

Think of it like this:

  • If I have an Orange in Location A, I can use FireServer(Orange) to transfer it to Location B

  • In Location B, I can use OnServerEvent:Connect(function(Player, Orange) so that we can get the Player’s Orange that was received from Location A

2 Likes

I understand this much, though, I don’t really understand where everything belongs in order to make this happen.

1 Like

AssetId.rbxl (31.3 KB)

2 Likes

A couple things then to note:

  • You’ll be using the FireServer() function & OnServerEvent Event, since you’re handling it from the client-server side

  • When you finish entering your ID into the TextBox, you can use FireServer() with the TextBox.Text inside 1 of your tuple arguments

  • The OnServerEvent Event will then wait for the event to be fired, then you can recieve your TextBox.Text property there & change the SurfaceGui

If you’re still confused, here’s a code sample:

--This should be on the client, not the server
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local TextBox = script.Parent.TextBox

--Handle your TextBox function after the player has finished entering the ID, inside there:
RemoteEvent:FireServer(TextBox)


--This should be on the server, not the client
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local GUI = workspace:WaitForChild("SurfaceGui")

RemoteEvent.OnServerEvent:Connect(function(Player, AssetID)
    GUI.ImageLabel.Image = "rbxassetid://"..tonumber(AssetID)
end)
1 Like
-- Client
local TextBox = script.Parent.TextBox -- GUI object which will hold the input
local Submit = script.Parent.Submit -- Submit button
local RemoteEvent = game.ReplicatedStorage:WaitForChild('RemoteEvent') -- Add RemoteEvent in ReplicatedStorage

Submit.MouseButton1Click:Connect(function()
    local Input = TextBox.Text
    if tonumber(Input) then -- Checks if input is a number
        RemoteEvent:FireServer(Input)
    end
end)

-- Server
local RemoteEvent = game.ReplicatedStorage:WaitForChild('RemoteEvent')
local SurfaceGui = workspace:FindFirstChild('SurfaceGui') -- Location of image

RemoteEvent.OnServerEvent:Connect(function(player,Input)
    SurfaceGui.ImageLabel.Image = 'rbxassetid://'..Input
end)
1 Like

Remote Events unlocks the advantage of server-client communication. Both server and client must be accessible to the remote event in order to communicate. ReplicatedStorage is already a great parent for it.

1 Like

Thanks everyone for the help. Seeing these examples makes it a lot more clear.