How to automatically change the text of a TextLabel

  1. What do you want to achieve?
    I would like to automatically change the text when the array changes

  2. What is the issue?
    As you can see with the script and the video, the value of the text doesn’t change at all, even tough the script is supposed to change (shown when I play the 2nd time)

  3. What solutions have you tried so far?
    I’ve tried checking on the wiki but nothing seems to be like my issue. I believe it has something to do with Text.Changed but i’ve no clue if I’m going in the right path.

This is the original script:

local function changeText()
	for i, v in pairs(rankArray) do
		local index
	
		index = i
		
		local nextRank = index + player.IndexValue.Value
		local currentRank = nextRank - 1
		
		print(v[nextRank].Name.." This is the next rank")
		print(v[currentRank].Name.." This is the current rank")
		
		currentRankName.Text = v[currentRank].Name
		currentBoostDelayText.Text = (v[currentRank].BoostTime.. " Seconds")
		currentCrownMultiplyText.Text = ("x"..v[currentRank].MultiplierCrown)
		currentTimeMultiplyText.Text = ("x"..v[currentRank].MultiplierTime)
		
		nextRankName.Text = v[nextRank].Name
		nextBoostDelayText.Text = (v[nextRank].BoostTime.. " Seconds")
		nextCrownMultiplyText.Text = ("x"..v[nextRank].MultiplierCrown)
		nextTimeMultiplyText.Text = ("x"..v[nextRank].MultiplierTime)
	end
end
local RankUpModule = {
	AllRanks = {
		[1] = {
			Name = "Noob",
			MultiplierTime = 1,
			MultiplierCrown = 1,
			BoostTime = 30,
		},
		[2] = {
			Name = "Beginner",
			Price = 12500, -- 12.5k
			MultiplierTime = 2.5,
			MultiplierCrown = 1.25,
			BoostTime = 28,
		},
		[3] = {
			Name = "Pro",
			Price = 90000, -- 90k
			MultiplierTime = 7,
			MultiplierCrown = 1.5,
			BoostTime = 26,
		},
		[4] =  {
			Name = "Masterful",
			Price = 325000, -- 325k
			MultiplierTime = 18,
			MultiplierCrown = 1.75,
			BoostTime = 24,
		},
		[5] = {
			Name = "Powerful",
			Price = 915000, -- 915k
			MultiplierTime = 43,
			MultiplierCrown = 2,
			BoostTime = 22,
		},
		[6] = {
			Name = "Master Mind",
			Price = 2500000, -- 2.5m
			MultiplierTime = 95,
			MultiplierCrown = 2.25,
			BoostTime = 20,
		},
		[7] = {
			Name = "Bluethoot",
			Price = 8650000, -- 8.65m
			MultiplierTime = 232,
			MultiplierCrown = 2.5,
			BoostTime = 19,
		},
		[8] = {
			Name = "Deez Nuts",
			Price = 17500000, -- 17.5m
			MultiplierTime = 411,
			MultiplierCrown = 2.75,
			BoostTime = 18,
		},
		[9] = {
			Name = "1234Test1234",
			Price = 54250000, -- 54.25m
			MultiplierTime = 777,
			MultiplierCrown = 3,
			BoostTime = 17,
		},
		[10] = {
			Name = "Break The Game",
			Price = 14150000000000, -- 14.15T
			MultiplierTime = 99999,
			MultiplierCrown = 99,
			BoostTime = 3,
		},
	}
}
2 Likes

I’m assuming you want to call the function whenever the players IndexValue is changed, you’ll need to use Changed (as you assumed), so it should look something like this I presume:

nextRank.Changed:Connect(function()
	changeText()
end)

Lmk if that works :smiley:

Yes that’s exactly what I wanted, but my IndexValue is a number value, meaning it can’t call the function .Changed, do you have any other idea of how I could call the function when my indexvalue changes?

1 Like

Not really sure then, I mean you could always use an IntValue instead? Or do you need to use a NumberValue for other scripts, etc.

1 Like

What about GetPropertyChangedSignal?

1 Like

I’ve no idea how to use that, did some research but still doesn’t seems to work

You don’t setup a connection inside the function. Establish it outside so that it exists without needing to create a new connection every time the function is called.

local function something(...) end
value:GetPropertyChangedSignal("Value"):Connect(something)
1 Like

because youre calling it inside itself, run it where needed, which is probably after the function declaration or just change it whenever the button is actually pressed. i see you have changetext called after, so you might want to put it there.

1 Like

the error is because GetPropertyChangedSignal checks if the specific property value changed, which in your case it would be for the IndexValue, not the Value itself.

do this instead

player.IndexValue:GetPropertyChangedSignal("Value"):Connect(changeText)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.