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

Text Label Scroller/Selector Displays values in wrong order and gets stuck?

local list = {"Aunt","Big","Cap'n","Captain","Chef","Chief","Coach",
"Colonel","Cool","Crazy","Daring","Deputy","Dippy","Doctor","Dr.","Elvin","Elvis",
"Eddy","Earl","Fancy","Fat","Good ol'","Grand ol'","Granny","Grumpy","Judge","Lady","Little","Loopy",
"Loud","Lucky","Madame","Miss","Mrs.","Noisy","Princess","Prof.","Queen","Sheriff","Silly","Skinny",
"Super","Ugly","Weird"}

local titledown = script.Parent.TitleDown
local titleup = script.Parent.TitleUp
local curNum = 4 -- since we have start in the middle use 2
local max = #list

-- ref to the text labels all in order
local txt3 = script.Parent.TitleUp.Name_3-- This is ontop = top text label
local txt2 = script.Parent.TitleUp.Name_2
local txt1 = script.Parent.TitleUp.Name_1
local txt0 = script.Parent.TitleUp.Name0-- this is the middle text label
local txt_1 = script.Parent.TitleUp.Name1
local txt_2 = script.Parent.TitleUp.Name2-- This is below = bottom text label

function showTxt()
	txt0.Text = list[curNum] -- the middle will always be accessible
	txt2.Text = list[curNum + 2]
	txt1.Text = list[curNum + 1]
	txt_1.Text = list[curNum - 6]
	-- some more advanced method	
	-- txt1.Text = list[curNum - 1] and list[curNum - 1] or list[max] 
	-- un tested but it used the logic shown here https://www.lua.org/pil/3.3.html	
	
	if list[curNum - 1] == nil then -- wouk out is we can do the logic
		txt3.Text = list[max] 
	else
		txt3.Text = list[curNum - 1]
	end
	
	if list[curNum + 1] == nil then 
		txt_2.Text = list[1] 
	else
		txt_2.Text = list[curNum + 1]
	end
	
end
	

titleup.MouseButton1Click:connect(function()
	curNum = curNum + 1
	if curNum > max then curNum = 1 end -- reset our number
	showTxt() -- update the text
end)

titledown.MouseButton1Click:connect(function()
	curNum = curNum - 1
	if curNum <= 0 then curNum = max end -- again the reset
	showTxt()
end)

showTxt()

Not sure what i did wrong here Kingdom5 but its not avting like it should anymore cri

1 comment

0

Let me try and fix this.

1 answer

This code should work. Sorry if it doesn't, I can't test it right now.

local list = {"Aunt","Big","Cap'n","Captain","Chef","Chief","Coach",
"Colonel","Cool","Crazy","Daring","Deputy","Dippy","Doctor","Dr.","Elvin","Elvis",
"Eddy","Earl","Fancy","Fat","Good ol'","Grand ol'","Granny","Grumpy","Judge","Lady","Little","Loopy",
"Loud","Lucky","Madame","Miss","Mrs.","Noisy","Princess","Prof.","Queen","Sheriff","Silly","Skinny",
"Super","Ugly","Weird"}

local titledown = script.Parent.TitleDown
local titleup = script.Parent.TitleUp
local curNum = 1

local labels = {}
for _,v in pairs (titleup:GetChildren()) do
	local num = tonumber(string.match(v.Name,"(%d+)") or string.match(v.Name,"-%d+")) -- finds the number of the label
	if num then
		labels[num] = v
	end
end

function showText()
	for i = -2,2 do -- iterates the through the labels
		labels[i].Text = list[curNum+i] or list[#list-i] or list[#list+i] -- sets the text, first catering for the middle label, then the upper ones, then the lower ones
	end
end

titleup.MouseButton1Click:connect(function()
    curNum = curNum + 1
    if curNum > #list then curNum = 1 end -- reset our number
    showTxt() -- update the text
end)

titledown.MouseButton1Click:connect(function()
    curNum = curNum - 1
    if curNum <= 0 then curNum = #list end -- again the reset
    showText()
end)

showText()

Hope I helped!

~TDP

4 comments

0

Players.sammiya1.PlayerGui.ToonMorphs.Toontorial.NamePanel.LocalScript:34: attempt to index field '?' (a nil value)

0

Where on my script is this?

0

Line 34 But im also guessing the text labels thing at line 11 may be a problem. The text labels in title up are named differently as seen in my post script. Hope this helps thanks

0

Ahh, I forgot to explain. For this to work, you would need to name the labels "AnyThingHere" followed by a number (-2 to 2, including 0). It also may be also bugging on Line 13 of my code, but tell me if it does.

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