Text in Surface Gui not changing

Hi everyone,

I have been working on a game and I have had this problem for a while now. The surface Gui doesn’t change to what the Server Script in the model says.

The text in the Surface Gui needs to change to the Combination that is chosen by the script. That does seem to work but when I try to set the text to the text created by the script it just does do anything. The code also doesn’t give any errors. I don’t know what is wrong because I am relatively new :sweat_smile:

This is my code:

-- Objects
local BottomBurger = script.Parent.BottomBurger
local TopBurger = game.ReplicatedStorage.BurgerStuff.TopBurger
local ScreenText = script.Parent.Screen.SurfaceGui.Frame.Ingredients.Text

-- Combinations
local Combinations = {
	{"Salade", "Salade", "Union"},
	{"Salade", "Salade", "Tomato"},
	{"Salade", "Salade", "Cheese"},
	{"Salade", "Union", "Union"},
	{"Salade", "Union", "Tomato"},
	{"Salade", "Union", "Cheese"},
	{"Salade", "Tomato", "Tomato"},
	{"Salade", "Tomato", "Cheese"},
	{"Salade", "Tomato", "Union"},
	{"Salade", "Cheese", "Cheese"},
	{"Salade", "Cheese", "Union"},
	{"Salade", "Cheese", "Tomato"},
	{"Union", "Union", "Salade"},
	{"Union", "Union", "Tomato"},
	{"Union", "Union", "Cheese"},
	{"Union", "Salade", "Tomato"},
	{"Union", "Salade", "Cheese"},
	{"Union", "Tomato", "Tomato"},
	{"Union", "Tomato", "Cheese"},
	{"Union", "Cheese", "Cheese"},
	{"Tomato", "Tomato", "Salade"},
	{"Tomato", "Tomato", "Union"},
	{"Tomato", "Tomato", "Cheese"},
	{"Cheese", "Cheese", "Salade"},
	{"Cheese", "Cheese", "Union"}
}

function GenerateBurger()
	local Combination = math.random(1, #Combinations)
	local ChoosenCombination = Combinations[Combination]
	local Ingredient_1 = ChoosenCombination[1]
	local Ingredient_2 = ChoosenCombination[2]
	local Ingredient_3 = ChoosenCombination[3]
	
	print(ChoosenCombination)
	local Text = ("I would like a burger with: " .. Ingredient_1 .. ", " .. Ingredient_2 .. ", " .. Ingredient_3 .. ".")
	ScreenText = Text
end

GenerateBurger()

The model:

1 Like

Does it correctly print in this line?

	print(ChoosenCombination)
1 Like

Hey there! I am not sure what could be the problem here but I think there Are local and side errors. Try to use remote events, Create a remote event and name whatever you want, In this case, I called “UpdateScreenText”, make sure to create It In replicated storage or fix the path

-- Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateScreenText = ReplicatedStorage:WaitForChild("UpdateScreenText")

local Combinations = {
    {"Salade", "Salade", "Union"},
    {"Salade", "Salade", "Tomato"},
    {"Salade", "Salade", "Cheese"},
    {"Salade", "Union", "Union"},
    {"Salade", "Union", "Tomato"},
    {"Salade", "Union", "Cheese"},
    {"Salade", "Tomato", "Tomato"},
    {"Salade", "Tomato", "Cheese"},
    {"Salade", "Tomato", "Union"},
    {"Salade", "Cheese", "Cheese"},
    {"Salade", "Cheese", "Union"},
    {"Salade", "Cheese", "Tomato"},
    {"Union", "Union", "Salade"},
    {"Union", "Union", "Tomato"},
    {"Union", "Union", "Cheese"},
    {"Union", "Salade", "Tomato"},
    {"Union", "Salade", "Cheese"},
    {"Union", "Tomato", "Tomato"},
    {"Union", "Tomato", "Cheese"},
    {"Union", "Cheese", "Cheese"},
    {"Tomato", "Tomato", "Salade"},
    {"Tomato", "Tomato", "Union"},
    {"Tomato", "Tomato", "Cheese"},
    {"Cheese", "Cheese", "Salade"},
    {"Cheese", "Cheese", "Union"}
}

function GenerateBurger()
    local Combination = math.random(1, #Combinations)
    local ChoosenCombination = Combinations[Combination]
    local Ingredient_1 = ChoosenCombination[1]
    local Ingredient_2 = ChoosenCombination[2]
    local Ingredient_3 = ChoosenCombination[3]
    
    print(ChoosenCombination)
    local Text = ("I would like a burger with: " .. Ingredient_1 .. ", " .. Ingredient_2 .. ", " .. Ingredient_3 .. ".")
    UpdateScreenText:FireAllClients(Text)
end

GenerateBurger()

Local:

-- Client Script (LocalScript)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateScreenText = ReplicatedStorage:WaitForChild("UpdateScreenText")
local ScreenText = script.Parent.Screen.SurfaceGui.Frame.Ingredients

UpdateScreenText.OnClientEvent:Connect(function(text)
    ScreenText.Text = text
end)

This Is just a reference, I am not sure what or how you want It to be, but this should be a better way. do not forget to update the parths

1 Like

Hey

I tried using your suggestion and it did do somthing but then gave me this error:
Schermafbeelding 2024-06-30 105401

Do you maybe know what I could do :sweat_smile:

Yeah, It gives me the list like this:
Schermafbeelding 2024-06-30 105651

Hello, the current approach you’re taking is fine since it’s a SurfaceGui, which can be viewed globally. However, the issue comes in when you reference to ScreenText here:

local ScreenText = script.Parent.Screen.SurfaceGui.Frame.Ingredients.Text

ScreenText becomes a string since you’re referencing to the Text property under “Ingredients”
A better idea would go like this:

local ScreenText = script.Parent.Screen.SurfaceGui.Frame.Ingredients

Then where you set the text:

ScreenText.Text = Text
1 Like

TYSM it workt!!!
Schermafbeelding 2024-06-30 112544

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.