Hey there, thank you for opening my question, I've asked this question a long time ago, but no one could answer it.
Question : Why is my Light Changer Script not working?
Here's the script!
local t = game.StarterGui.ChangeGUI.Text local weather = game.ServerStorage.zomApocalypseWeather if t.Text "example" then weather.Parent = game.Lightning if t.Text "example2" then weather.Parent = game.ServerStorage end
Any understandable help would mean so much to me. Thanks for reading this!
Hi BuzzKillGT! It looks like this script could use some improvements. This question is also lacking some information, but I will do the best I can to help you out. :)
I noticed at the beginning of the script, you seem to be attempting to change a non-existent property.
local t = game.StarterGui.ChangeGUI.Text
It seems you are attempting to change a "ScreenGui's" property, although.. ScreenGui's do not have a text property. (Woops!) However, we can add a text label to the ScreenGui.
You can add the object manually, or insert the object using one of ROBLOX's built in functions called "Instance.new()"
Here is an edited version of your script with that function implemented.
local ui = game.StarterGui:WaitForChild("ChangeGUI") local t = Instance.new("TextLabel", ui) local weather = game.ServerStorage.zomApocalypseWeather if t.Text "example" then weather.Parent = game.Lightning if t.Text "example2" then weather.Parent = game.ServerStorage end
There! Now we have some text in our gui. Although, it looks like this script still needs some improvements.
Your script has two if statements, and only 1 end. Your if statements also are a bit broken, and to be honest. You only need 1 if statement for this script. :b
Lets out this to work, i'll do my best to explain along the way, but here is a link that may help you in the future!
https://www.robloxdev.com/articles/Conditional-Statements-in-Lua
This link contains a lot of useful information, so please consider taking the time to read through it.
Now lets fix up this script.
local ui = game.StarterGui:WaitForChild("ChangeGUI") local t = Instance.new("TextLabel", ui) local weather = game.ServerStorage.zomApocalypseWeather if t.Text == "example" then weather.Parent = game.Lightning --uh oh we had a typo here! I've replaced "Lightning" with "Lighting"..Lightning is not a child of game, and probably dosnt exist tbh.-- --"==" means "is equal to" or "is exactly equal to" so if the arguments do not match, the commands after "then" wont run (until you close your if statement of course) -- elseif t.Text == "example2" then weather.Parent = game.ServerStorage --elseif is a really useful statement that goes after an if in an if..elseif block of code. If the first argument does not match, the script will check if the second argument matches. If either match, the commands specified will run. Otherwise, the script will ignore this block of code until called to run it again.-- end --we don't need 2 ends anymore now that we only have 1 if statement. I hope this helps! Btw in a Lua script, anything between double dashes (like this) will be completely ignore by the script. Hope I helped!--
This concludes my answer, I hope I helped! Let me know if you have anymore questions by commenting on this answer.
You're missing an end
local t = game.StarterGui.ChangeGUI.Text local weather = game.ServerStorage.zomApocalypseWeather if t.Text "example" then weather.Parent = game.Lightning end if t.Text "example2" then weather.Parent = game.ServerStorage end