Can't change text.Value via script

Hello, it is LocalScript in ScreenGui.

But it won’t change the text when you clicked UpgradeButton.

Anyone can help?

upgradeButton.MouseButton1Click:Connect(function()
	local UpgradeVal = player.sheets.Upgrade.Value
	local currentUpgrade = Module.upgradePrices[UpgradeVal+1]
	local localplayer = game.Players.LocalPlayer
	local multiplier = player.sheets.UpgradeMulti.Value
	local currenttext = player.PlayerGui.Upgrade.Frame.Current.Text

	if player.leaderstats.Strength.Value >= currentUpgrade then
		player.leaderstats.Strength.Value -= currentUpgrade
		UpgradeVal = UpgradeVal + 1
		multiplier = multiplier + 1
		currenttext = "Current Power: x"..tostring(multiplier)
		
		local upvalue = UpgradeVal
		RS.UpgradeVal:FireServer(upvalue,localplayer)
		local newValue = player.leaderstats.Strength.Value
		RS.UpdateValue:FireServer(newValue, localplayer)
		local multivalue = multiplier
		RS.UpdateMulti:FireServer(multivalue,localplayer)
	else
		print("Not enough Strenght")
	end

end)

When you first define currenttext, you define it as the text of the button, which is a string. That would look something like this:

local currenttext = "Whatever text the button has"

If all you do is re-define this variable to another string of text, you’re basically doing:

local currenttext = "Whatever text the button has"
currenttext = "New text"

To properly update the text on the button, you need to do so using the Text property:

local currentlabel = player.PlayerGui.UpgradeFrame.Current
currentlabel.Text = "Current Power: x"..tostring(multiplier)
2 Likes

thanks bro, it worked right now

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