String.format doesn't work

I am making a pre-run shop for my doors but bad game, everything is fine right now except for one thing
string.format only works once.

repeat wait() 
	
until

game:IsLoaded() == true

local time_left = 30
local DS = game:GetService('DataStoreService')


local player_knobs = game.Players.LocalPlayer:FindFirstChild('leaderstats').Knobs

function close()
	script.Parent:Destroy()
end

local shopthing = script.Parent.shop_main
local all_items = shopthing:GetChildren()

local items_to_buy = {}
local total_price = 0



coroutine.wrap(function()
	for _,item in ipairs(all_items) do
		if item:IsA('TextButton') then
			if item.Name == "ItemShop" then
				local defualt_color = item.UIStroke.Color
				
				item.MouseButton1Down:Connect(function(x,y)
					if not item:FindFirstChild('yes') then
						local mhm = Instance.new('BoolValue', item)
						mhm.Name = "yes"
						
						item.UIStroke.Color = Color3.new(0,1,0)
						total_price += item:GetAttribute('Price')

						print(total_price)
						table.insert(
							items_to_buy,
							item.item.Value
						)
						
					elseif item:FindFirstChild('yes') then
						item:FindFirstChild('yes'):Destroy()
						
						item.UIStroke.Color = defualt_color
						total_price -= item:GetAttribute('Price')

						print(total_price)
						
						table.remove(
							items_to_buy,
							table.find(items_to_buy,item.item.Value)
						)
					end
				end)
				
			end
		end
	end
end)()
-- THIS LINE
coroutine.wrap(function()
	while wait() do
		script.Parent.TextButton.Text = string.format(script.Parent.TextButton.Text, total_price)
		print(total_price)
	end
end)()

The output does print the total price, but the price shown on the gui is still 0. How can i fix this?

Read what you’re doing, you’re not storing the format.

local format = script.Parent.TextButton.Text
-- inside the while loop
script.Parent.TextButton.Text = string.format(format, total_price)

nevermind, i forgot to put )() at the end of coroutine.wrap(function()

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