Question About Text Setting


I’m trying to make it so text is set to a specific thing after something (code below). Some reason it doesn’t change at all. No errors, etc.


local RS = game.ReplicatedStorage
local SG = game.StarterGui
local items= {"Grapes", "Apples", "Toilet Paper", "Paper", "Stapler", "Chair", "Laundry Basket", "Bike", "Bandage", "Bananas", "Salad", "Tomatoes", "Light Bulbs", "Batteries", "Bed", "Carpet", "Sheet", "Blanket", "Vaccume", "Broom", "Chemicals", "Toothbrush", "Lotion", "Hair Brush", "Sticker", "Plushie", "Toy Car", "Toy Bricks", "Toy Rocket Launcher", "Sign", "Poster", "Treadmill", "Weights", "Fishing Pole", "Fishing Bait", "Spatula", "Timer", "Towel", "Kitchen Spoon"}

function main()
	local GetPrice = math.random(1,175)
	local GetItem = items[math.random(1, #items)]
	SS.Main.Item.Value = GetItem
	SS.Main.Price.Value = GetPrice
	SG.Main.Frame.Item.TextLabel.Text = GetItem
	SG.Main.Frame.Price.TextLabel.Text = GetPrice


Where is this code being handled? Is it on the server or on the client?

Is it in a ServerScript or a LocalScript?

It’s being handled with a serverscript.

Is SS defined earlier in the script, or did you mean to type RS?

When a player joins the game, the StarterGui is instantiated and sent to the player’s machine. Thus, resulting in their own, unique instance of the GUI.

The result of your design is causing the script to change the default content of the GUI. If another player were to join, they’d have the GUI instantiated to their machine and they’re going to see the changes.

You can setup a RemoteFunction from a LocalScript, then return this information from the server and have the player’s machine update their own GUI respectively.


local SG = game.StarterGui
local SS = game.ServerStorage

All defined above.

1 Like

So send the getprice/getitem from the main script to a local script?


You’re editing the starting gui instead of the player’s gui

You’re trying to do it from StarterGui (why many people are doing this) which won’t work

use game.Players.LocalScript:WaitForChild(“PlayerGui”)

Oh, but cause you’re using a remote, in your remote, make a parameter to get the player.

Have a LocalScript from the client’s machine call a RemoteFunction which resides in ReplicatedStorage.

The server will listen for a call to that RemoteFunction. In the event of a call, it will run the code you’ve provided above.

Instead of having the following on the server:

SG.Main.Frame.Item.TextLabel.Text = GetItem
SG.Main.Frame.Price.TextLabel.Text = GetPrice

Have it return the result instead as follows:

return GetItem, GetPrice

The LocalScript that fired the RemoteFunction would look something like this:

local PG = game.Players.LocalPlayer.PlayerGui;

local item, price = RemoteFunction:InvokeServer()
PG.Main.Frame.Item.TextLabel.Text = item
PG.Main.Frame.Price.TextLabel.Text = price

Edit: SG will have to be the PlayerGui. You can get that from a LocalScript by doing the folllowing:

game.Players.LocalPlayer.PlayerGui.(The GUI path here)

1 Like