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

Why is this not changing the colour and text of this Gui?

Asked by
RoboFrog 400 Moderation Voter
9 years ago

I've finally gotten a label system to work, however, I'm now encountering a new snag -- it's not wanting to change the text and colour. I've currently got this snippet of the script to examine:

local objname = mouse.Target.Parent.Name

if objname == "Wall1" then
            local objtru = objname == "Wall1"
            gui3.Text.Text = "Mud Wall"
            gui3.Text.BackgroundColor3 = Color3.new(158, 158, 158)
            gui3.Text.Visible = objtru
            wait(.3)
            end

This isn't the full script of course, but it should be enough. This is all inside of a local script. The function holding this activates whenever the mouse moves. The line gui3.Text.Visible = objtru activates perfectly fine, meaning that this code block in the if runs.

I see no reason why it won't change the text or the colour.

Thank you for reading, and I look forward to finding out why this is occurring!

1 answer

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

There are a few problems with this that I can see.


The first is in the first line:

local objname = mouse.Target.Parent.Name

mouse.Target can be nil, when you are pointing at the sky. In that case, this would result in an error ("cannot index 'Parent' of 'nil'"), so we should first check that mouse.Target is in fact not nil.


Your use of objtru is superfluous. It will always be true since it is in the body of an if ensuring that.

Probably you meant to move line 4 and line 7 outside of the if statement.


You haven't defined gui3 in this script. Probably you forgot to define it or just didn't include it in this snippet.


The Color3.new constructor actually uses values between 0 and 1, not 0 and 255 like shown in the Properties tab. Divide the numbers by 255 to get the appropriate conversion.

0
The first thing (about the sky) is very helpful -- I've been having issues with that for a while! As for the objtru, I can see what you mean. I've got a similar statement which can be false elsewhere in the script, so I'll probably just make that set to true. Gui3 is defined elsewhere, I just forgot to add it. And thank you for the color conversion, I'm used to RGB from other languages. Did you h RoboFrog 400 — 9y
0
happen to notice the issue with the text, though? RoboFrog 400 — 9y
0
Oh, wait, disregard the last question -- I just noticed that the text was the same colour as white, which is what the colour was showing as before fixing it. Thank you for the help! RoboFrog 400 — 9y
Ad

Answer this question