Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Light Changer Script not working?

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!

1 comment

0

You need to put 2 ends

2 answers

✓ Accepted answer

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.

5 comments

0

I've tried to put "elseif" in the script, however it got the red line below it for reasons.

0

"Text" is actually the name of the text label, it isn't the property in a screen GUI.

0

"Text" is actually a changing text, just to let you know.

0

For anyone curious, we took this up in dm's. So if anyone is having the problem above, contact me for a full explanation.

0

Trin#4889 dont read this :3

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

2 comments

0

You left out a lot of stuff ;b

0

cough i tried doing that but cough it has a red line

This discussion is preserved as it was. New answers, comments, and votes are closed.