I have a script and it is supposed to change the brick colour and material when the GUI says a certain text. It is not working. Here is the script:
local grass = script.Parent
if game.StarterGui.ScreenGui.TextLabel.Text == “Summer” then
grass.Transparency = 0
if game.StarterGui.ScreenGui.TextLabel.Text == “Autumn” then
grass.Transparency = 0
grass.BrickColor = BrickColor.new(“Deep orange”)
if game.StarterGui.ScreenGui.TextLabel.Text == “Winter” then
grass.Transparency = 0
grass.BrickColor = BrickColor.new(“White”)
grass.Material = Enum.Material.Snow
if game.StarterGui.ScreenGui.TextLabel.Text == “Spring” then
grass.Transparency = 0
end
Also some things about the script:
Its not a local script, its in the part called “Snow”
Use PlayerGui not StarterGui because all of the GUI is cloned there. Meaning all of the game’s UI is visible from the PlayerGui, the StarterGui only serves as a template that clones over to the PlayerGui.
Code sample:
local player = game.Players.LocalPlayer
local ui = player:WaitForChild("PlayerGui")
if ui.ScreenGui.TextLabel.Text == “Summer” then
grass.Transparency = 0
if ui.ScreenGui.TextLabel.Text == “Autumn” then
grass.Transparency = 0 --please indent
grass.BrickColor = BrickColor.new(“Deep orange”)
end --you need an end for each if statement, I added one in
if ui.ScreenGui.TextLabel.Text == “Winter” then
grass.Transparency = 0
grass.BrickColor = BrickColor.new(“White”)
grass.Material = Enum.Material.Snow
end --another end
if ui.ScreenGui.TextLabel.Text == “Spring” then
grass.Transparency = 0
end
Changes to GUI won’t really work from the server. You need to set up a remote event to fire to the client whenever an if statement is true.
I’d like to elaborate on this and explain a little further.
StarterGui is a location present for the convenience of the developer. Essentially, it is a quick way for you to place starter items in a player’s GUI.
When a client joins the game, the engine automatically clones all the contents of the service into the connecting client’s PlayerGui.
So, essentially, you are changing the colour of what will be displayed in the GUI for the next connecting client. If you do this on the client side, that does nothing (because of filtering etc.)
So, if you want to change the properties of a GUI object in real time, you need to get a reference to the client. Consider using something such as game.Players.LocalPlayer. From there, change the properties of the UI you wish.
So, to sum up, you’re changing the properties on the wrong object and need to modify your code to change the LocalPlayer.PlayerGui object.
If you want to quickly fix this, you can literally just run a find and replace on game.StarterGui replacing with what I mentioned above.