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

Changing SurfaceGUI text using tables?

What I'm trying to do is have any amount of titles/content, and will display in order.

For example

local titles = { 
    "Need Help?"; --Title 1
    "REMEMBER:"; --2
    "REMEMBER:"; --3
}

local content = { 
    "Use the 911 call box to get help!"; --Content 1
    "Stick to the speed limit! People are trying not to get hurt!"; --2
    "Trespassing is a crime! Trespassing on other's properties will get you arrested!"; --3
}

--The title displays in the corresponding textLabel
--And the content displays in the corresponding textLabel

My full code

local nextMsg = 20

local titles = { --Titles
    "Need Help?";
    "REMEMBER:";
    "REMEMBER:";
}

local content = { --The content
    "Use the 911 callbox to get help!";
    "Stick to the speed limit! People are trying not to get hurt!";
    "Trespassing is a crime! Trespassing on other's properties will get you arrested!";
}
math.randomseed(os.time())
local title = script.Parent.Title
local content = script.Parent.Content
while wait()  do 
    for _, r in ipairs(titles) do
		title.Text = titles[_];
		content.Text = content[_];
		wait(nextMsg)
    end
end

If you don't understand what I mean. Please feel free to ask!

[UPDATE]

I am now receiving the error,

15:44:09.226 - 1 is not a valid member of TextLabel
15:44:09.230 - Script 'Workspace.Model.Surface GUI.SurfaceGui.Script', Line 20
15:44:09.233 - Stack End

1 comment

0

try changing title.Text = titles[_] into title.Text = r, and you need a new loop for content, or use numeric.

1 answer

✓ Accepted answer

This is what I have working in my Roblox studio

local nextMsg = 2

local titles = { --Titles
    "Need Help?";
    "REMEMBER:";
    "REMEMBER:";
}

local content = { --The content
    "Use the 911 callbox to get help!";
    "Stick to the speed limit! People are trying not to get hurt!";
    "Trespassing is a crime! Trespassing on other's properties will get you arrested!";
}
math.randomseed(os.time())
--local title = script.Parent.Title
--local content = script.Parent.Content
while wait()  do 
    for i, r in ipairs(titles) do
        print(titles[i]);
        print(content[i]);
        wait(nextMsg)
    end
end

output:-

Need Help?
Use the 911 callbox to get help!
REMEMBER:
Stick to the speed limit! People are trying not to get hurt!
REMEMBER:
Trespassing is a crime! Trespassing on other's properties will get you arrested!

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