Look at the description

Hello developers i remaked the my system rebirth, but it working only for 1 button
ScreenShot:

script:

cd = false
local plr = game.Players.LocalPlayer

local selecting = script.Parent.Parent.Selecting
local selected = script.Parent.Parent.Selected

local module = require(game.ReplicatedStorage.AbbreviateNumber)
for _, i in pairs(script.Parent:GetDescendants()) do

	print(i.Name)

	if i:IsA("TextButton") then		
		i.MouseButton1Click:Connect(function()
			if selecting.Value == false then
				print("ok")
				if (plr.leaderstats.Rebirth.Value*i.priceadding.Value) +i.priceadding.Value <= plr.leaderstats.Clicks.Value then
					game.ReplicatedStorage.Events.Rebirth:FireServer(i.rebirths.Value)
				end
			else
			selecting.Value = false
			selected.Value = i.Name
			end
		end)
	while wait() do
		if selecting.Value == false then
			if (plr.leaderstats.Rebirth.Value*i.priceadding.Value) +i.priceadding.Value <= plr.leaderstats.Clicks.Value then
				i.Text = i.rebirths.Value.." Rebirths BUY"
				i.BackgroundColor3 = Color3.new(0.666667, 1, 0.498039)
			else
				i.Text = i.rebirths.Value.." Rebirths ".. module.abbreviate((plr.leaderstats.Rebirth.Value*i.priceadding.Value)+i.priceadding.Value)
				i.BackgroundColor3 = Color3.new(0.501961, 0.760784, 1)
			end
		else
			i.Text = i.rebirths.Value.." Rebirths Select"
		end
	end
	end
end

any problems?

1 Like

you put an infinitely running while loop in the for loop!
you should try to find a better way to implement this or put the while loop in it’s own thread via. task.defer

1 Like

ye i got the error in the code, okey i will try task.defer

1 Like

oh, can you send a example of task.defer i never work with this

1 Like

the value i will forever be stuck on one because the while loop wont let them move on!

for i = 1, 10 do
  while true do
    print('you shall not pass!')
  end
end

when you add task.defer it makes it so that the while loop runs on its own thread, kind of like creating a script inside of a script

for i = 1, 10 do
  task.defer(function()
    while true do
      print('you passed :(')
    end
  end)
end

print('yay I passed :)')

I generally do not recommend this approach and just use it as a last resort, please look for a better solution to this problem. but if you cant use this all you want

1 Like

Oh it worked thank you for the help!