Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't my script with IF and THEN work?

Asked by 5 years ago
Edited 5 years ago

Hey, I really need your help, I can't seem to make the script to work.

~~~~~~~~~~~~~~~~~

local speedRunWeather = game.ServerStorage.speedRunWeather
local t = game.StarterGui.changeGUI.Text

if t.Text "Hey, this is a text." 
then speedRunWeather.Parent = game.Lightning

I would really appreciate if you guys could help me, thank you!

(filtering enabled, i put the script in serverscriptserver)

2 answers

Log in to vote
1
Answered by
CPF2 406 Moderation Voter
5 years ago
Edited 5 years ago

an if statement should be formatted like this

if foo == bar then
print('Hello World!')
end

EDIT:

so your code should be like this.

local speedRunWeather = game.ServerStorage.speedRunWeather
local t = game.StarterGui.changeGUI

if t.Text == "Hey, this is a text." then
speedRunWeather.Parent = game.Lightning
end

It also should be noted that when changing text on a gui, don't save the text as a variable,

Variables in RLua have many types (ex. Bool, String, Instance, etc.)

When you save a variable like you did before

Reference:

local t = game.StarterGui.changeGUI.Text

It saves the Text property of the Instance as a String variable. This means that when you change it later in your code, it isn't changing the text that is on the TextLabel, it is changing the Text variable.

Example:

local textLabel = Instance.new('TextLabel')
textLabel.Text = 'foo'

local Text = textLabel.Text -- The variable "Text" now equals 'foo'

print(Text) -- Prints 'foo'

textLabel.Text = 'bar' -- We set the TextLabel's text to 'bar'

print(Text) -- Still prints 'foo'

The way to do it correctly is to save the Text variable as the TextLabel's Instance. (Or just reference the TextLabel directly every time)

Example:

local textLabel = Gui.Notification
textLabel.Text = 'foo'

-- or just do

Gui.Notification.Text = 'foo'

Doing this allows you to change the instance's Text property directly, instead of what you did before (saving the text property as a variable).

0
No, He needs to change the text in the playergui not the startergui. DevingDev 346 — 5y
0
No, he said clearly that the script is in ServerScriptService CPF2 406 — 5y
0
Any change in the startergui when the game is running wont replicate to the playergui. DevingDev 346 — 5y
0
He isn't changing the startergui, he is checking if an already present textlabel in the startergui has a certain text on it, if it does, he changes the lighting CPF2 406 — 5y
View all comments (2 more)
0
lol sorry my bad. DevingDev 346 — 5y
0
mm this is compatible to filtering enabled right.. BuzzKillGT 33 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

BuzzKillGT for line 4 you did:

if t.Text "Hey, this is a text."

you forgot to add a equal sign, so it didnt work -

if t.Text == ("Hey, this is a text.") then

and dont use use variables to store text, because if u change the text it doesnt update it, so use it directly(idk how to say it lol).

0
Hehehe, I'll try your solution tommorow. BuzzKillGT 33 — 5y
0
k User#23365 30 — 5y
0
You forgot to put the "end". Bilinearly 58 — 5y
0
ik, i was giving an example, plus roblox would automatically put an end anyways, do u think that im that stupid? User#23365 30 — 5y

Answer this question