Hello! I want to make a script that will process button clicks, I did it but I probably made a mistake in if Button.Name == ButtonsHandler[Button.Name] and not Debounce then
ButtonHandler Script:
--// Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--// Variables
local Buttons = workspace.Buttons:GetDescendants()
--// Modules
local ButtonsHandler = require(ReplicatedStorage.Modules.Buttons)
--// Other
local Debounce = false
print(ButtonsHandler)
for _, Button in pairs(Buttons) do
if Button.Name == ButtonsHandler[Button.Name] and not Debounce then
Debounce = true
print(Button.Name.." Found")
local stat = ButtonsHandler[Button.Name].Stat
local nextStat = ButtonsHandler[Button.Name].NextStat
local amount = ButtonsHandler[Button.Name].Amount
local cost = ButtonsHandler[Button.Name].Cost
local Frame = Button.Stats.Frame
local Amount = Frame.Amount
local Cost = Frame.Cost
Amount.Text = amount.." "..stat
Cost.Text = cost.." "..nextStat
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
ButtonHandler Module:
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,
},
}