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

Why won't my TextLabel's text change from script?

Asked by 9 years ago

Please help me fix this problem. I want it to change in every # seconds.

p = script.Parent.Text


while true do
    wait(1)

    p = ("Hint #1 - Say Status to open your Stats!")

    wait(5)

    p = ("Hint #2 - Increase your Int to make your mana regen higher!")

    wait(5)

    p = ("Hint #3 - Make sure you favorite and Thumbs up the game for more updates!")

    wait(10)

    p= ("Hint # 4 - If you want more classes added, just buy the New class gamepass and PM me the name of your Class. It will be put in the game within two weeks.")

    wait(15)
end

2 answers

Log in to vote
2
Answered by 9 years ago

How's this?

    local messages = { -- Change me
        "I am the best";
        "No you're not";
        "Yes I am!";
        "Really, you're not!";
    }

    local label = script.Parent

    while true do
        for _, text in ipairs(messages) do
            label.Text = text
            wait(10)
        end
    end

Here, we have made the code much more readable by using a for loop to loop through all of the messages in the messages table. However, this will only run once, so we need to wrap a while loop around it.

Another problem is you're setting p to script.Parent.Text, which is a string, and nothing else. By setting p again, you're just overwriting the variable to another string. No reference to the TextLabel object there.

Ad
Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Code Fixes

When you set the 'p' variable to the Text property of script.Parent, then the variable becomes a string of whatever text that was, you can't change the Text property by making a variable equivelant to the Text property..

So, make the variable script.Parent and index the Text property when changing it.


Efficiency Fixes

I suggest making a table full of tables with the first index being the text and the second being the time to wait, then iterate through the table and input those values for the text and wait time.. it looks more asthetically pleasing and is more efficient(:


Code

local p = script.Parent
local msgs = {
    {'Hint #1 - Say Status to open your Stats!',5}, --Text, Time
    {'Hint #2 - Increase your Int to make your mana regen higher!',5},
    {'Hint #3 - Make sure you favorite and Thumbs up the game for more updates!',10},
    {'Hint # 4 - If you want more classes added, just buy the New class gamepass and PM me the name of your Class. It will be put in the game within two weeks.',15}
}

while true do
    for i,v in ipairs(msgs) do
        p.Text = v[1]
        wait(v[2])
    end
end

Answer this question