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.
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)
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)
-- 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)
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.