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

My script isnt working?

Asked by 10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I am trying to make a screen gui for my nuclear reactor that says the core status... it wont work?!?

heres the screen gui text changer script:

1while true do
2script.Parent.TextBox.Text = "Core Status : " .. game.Workspace.GuiValue
3wait(.1)
4end

heres the core temp monitor and value changer script:

01while true do
02if game.Workspace.Temp.Current.Value > -276 then
03    game.Workspace.GuiValue.Value = "Core too cold!"
04    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.b = 255
05    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.g = 0
06    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.r = 0
07end
08end
09 
10while true do
11if game.Workspace.Temp.Current.Value > 0 then
12    game.Workspace.GuiValue.Value = "Core stable"
13    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.b = 0
14    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.g = 255
15    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.r = 0
View all 26 lines...

This may be the dumbest script EVER, i dont know, i am bad at scripting, please help!

2 answers

Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
10 years ago

while loops are yuck. Read about the Changed event. Making changes to the StarterGui won't be seen until after the player respawns and all of the ScreenGuis are loaded into their PlayerGui again. Another thing is what Tesouro said- r, g, and b are read only values. You have to reset the whole color using Color3.new. I'll re-write your script to show you how I would do it.

"screen gui and text changer script," you don't need the other one now.

01local curTemp = Workspace.Temp.Current
02local msg = script.Parent.TextBox -- I'd consider changing this to a TextLabel if you don't want people to be able to edit it in-game
03 
04curTemp.Changed:connect(function(temp)
05    if temp <= -276 then -- I think this is what you were getting at :)
06        msg.Text = "Core too cold!"
07        msg.BackgroundColor3 = Color3.new(0, 0, 1) -- parameters for Color3.new go between 0 and 1
08    elseif temp > -276 and temp < 276 then
09        msg.Text = "Core stable"
10        msg.BackgroundColor3 = Color3.new(0, 1, 0)
11    elseif temp >= 276 then
12        msg.Text = "Core overheat!"
13        msg.BackgroundColor3 = Color3.new(1, 0, 0)
14    end
15end)
0
thank you!!! it worked!! :D The_Sink 77 — 10y
Ad
Log in to vote
-1
Answered by
Tesouro 407 Moderation Voter
10 years ago

BackgroundColor3.r or g or b are read-only properties, you can't change them like that. Have a look at this and this.

Also, you placed a lot of while true do loops and all without wait, that is wrong.

And in the second line of the first script you forgot the .Value in the end.

It may look like this:

01while true do
02if game.Workspace.Temp.Current.Value > -276 then
03    game.Workspace.GuiValue.Value = "Core too cold!"
04    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.b = 255
05    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.g = 0
06    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.r = 0
07end
08if game.Workspace.Temp.Current.Value > 0 then
09    game.Workspace.GuiValue.Value = "Core stable"
10    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.b = 0
11    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.g = 255
12    game.StarterGui.CoreStatusGui.TextBox.BackgroundColor3.r = 0
13end
14if game.Workspace.Temp.Current.Value > 0 then
15    game.Workspace.GuiValue.Value = "Core Overheat!"
View all 21 lines...

Answer this question