Buttons not working

for _, data in ButtonsHandler do
	for _, Button in Buttons:GetDescendants() do
		if Button:IsA("BasePart") and not Debounce then
			Debounce = true
			
			local Clone = ButtonStatsGui:Clone()
			Clone.Parent = Button

			local stat = data["Stat"]
			local nextStat = data["NextStat"]
			local amount = data["Amount"]
			local cost = data["Cost"]

			local Frame = Button.ButtonStats.Frame
			local Amount = Frame.Amount
			local Cost = Frame.Cost

			Amount.Text = amount.."  "..nextStat
			Cost.Text = cost.."  "..stat

			Button.Button.Touched:Connect(function(hit)
				if hit.Parent:FindFirstChildOfClass("Humanoid") then
					local Player = Players:GetPlayerFromCharacter(hit.Parent)
					if Player then
						local cash = Player.leaderstats.Cash
						local multi = Player.leaderstats.Multiplier
						local rebirths = Player.leaderstats.Rebirths

						if stat == "Robux" then
							-- Buy Robux / Gamepass
						elseif stat == "Cash" then
							if cash.Value >= cost then
								cash.Value -= cost
								multi.Value += amount
							end
						elseif stat == "Multi" then
							if multi.Value >= cost then
								multi.Value -= cost
								rebirths.Value += amount
							end
						end

						task.wait(0.2)
						Debounce = false
					end
				end
			end)
		end
	end
end

return
	{
		["Multiplier1"] = {
			Stat = "Cash",
			NextStat = "Multi",
			Amount = 1,
			Cost = 25,
		},
		["Multiplier2"] = {
			Stat = "Cash",
			NextStat = "Multi",
			Amount = 5,
			Cost = 150,
		},
		["Multiplier3"] = {
			Stat = "Cash",
			NextStat = "Multi",
			Amount = 10,
			Cost = 400,
		},

		--//

		["Rebirths1"] = {
			Stat = "Multi",
			NextStat = "Rebirths",
			Amount = 10,
			Cost = 2500,
		},
		["Rebirths2"] = {
			Stat = "Multi",
			NextStat = "Rebirths",
			Amount = 50,
			Cost = 15000,
		},
		["Rebirths3"] = {
			Stat = "Multi",
			NextStat = "Rebirths",
			Amount = 400,
			Cost = 150000,
		},
	}

1 Like

Correct me if I’m wrong, but could this be because of the debounce? By what I see, only one button might be activated (due to the Debounce variable immediately being changed at the start of the loop). Make sure to use the debounce after the button is touched, not before (although with the current way this is written, only one button should be active at a time due to the debounce).

Additionally, being descriptive regarding your problem helps whoever is trying to figure it out by a lot. Hope this helps!

2 Likes

image
unfortunately it didn’t help

2 Likes

Any error you seen in the console?

2 Likes

there are no errors in the console

1 Like

[quote=“NotAngel, post:1, topic:3118392, username:Dozetopgg”]

for _, data in ButtonsHandler do
	for _, Button in Buttons:GetDescendants() do
		if Button:IsA("BasePart") and not Debounce == true then
			Debounce = true
			
			local Clone = ButtonStatsGui:Clone()
			Clone.Parent = Button

			local stat = data["Stat"]
			local nextStat = data["NextStat"]
			local amount = data["Amount"]
			local cost = data["Cost"]

			local Frame = Button.ButtonStats.Frame
			local Amount = Frame.Amount
			local Cost = Frame.Cost

			Amount.Text = amount.."  "..nextStat
			Cost.Text = cost.."  "..stat

			Button.Button.Touched:Connect(function(hit)
				if hit.Parent:FindFirstChildOfClass("Humanoid") then
					local Player = Players:GetPlayerFromCharacter(hit.Parent)
					if Player then
						local cash = Player.leaderstats.Cash
						local multi = Player.leaderstats.Multiplier
						local rebirths = Player.leaderstats.Rebirths

						if stat == "Robux" then
							-- Buy Robux / Gamepass
						elseif stat == "Cash" then
							if cash.Value >= cost then
								cash.Value -= cost
								multi.Value += amount
							end
						elseif stat == "Multi" then
							if multi.Value >= cost then
								multi.Value -= cost
								rebirths.Value += amount
							end
						end

						task.wait(0.2)
						Debounce = false
					end
				end
			end)
		end
	end
end

Try this script

1 Like

Can I see the rewritten code, please?

1 Like

nothing has changed buttons dont work

1 Like
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Objects = ReplicatedStorage.Objects.GUI.Other
local Configs = ReplicatedStorage.Modules.Client.Configs

local ButtonsHandler = require(Configs.ButtonsConfig)

local ButtonStatsGui = Objects.ButtonStats
local Buttons = workspace.Buttons

for _, data in ButtonsHandler do
	for _, Button in Buttons:GetDescendants() do
		if Button:IsA("BasePart") then

			local Clone = ButtonStatsGui:Clone()
			Clone.Parent = Button

			local stat = data["Stat"]
			local nextStat = data["NextStat"]
			local amount = data["Amount"]
			local cost = data["Cost"]

			local Frame = Button.ButtonStats.Frame
			local Amount = Frame.Amount
			local Cost = Frame.Cost

			Amount.Text = amount.."  "..nextStat
			Cost.Text = cost.."  "..stat

			Button.Button.Touched:Connect(function(hit)
				if hit.Parent:FindFirstChildOfClass("Humanoid") then
					local Player = Players:GetPlayerFromCharacter(hit.Parent)
					if Player then
						local cash = Player.leaderstats.Cash
						local multi = Player.leaderstats.Multiplier
						local rebirths = Player.leaderstats.Rebirths

						if stat == "Robux" then
							-- Buy Robux / Gamepass
						elseif stat == "Cash" then
							if cash.Value >= cost then
								cash.Value -= cost
								multi.Value += amount
							end
						elseif stat == "Multi" then
							if multi.Value >= cost then
								multi.Value -= cost
								rebirths.Value += amount
							end
						end
						
					end
				end
			end)
		end
	end
end

1 Like

did you try adding print statements to see where the script stops?

1 Like

Can I see the buttons classname?

1 Like

image

1 Like

I added a check to see if the button is a folder and now the buttons work, but I constantly change my gui values

1 Like

I think you need pairs() on the for _, data in ButtonsHandler ()