So I’m making a Trail Shop System but when I click the Buy/Equip Button it’s acting it was clicked 4 times I tried making a cooldown but it’s still act being clicked 4 times

local IsPurchased = TrailFolder:FindFirstChild(FrameC.Name)
local CooldownButton = false
ToggleButton.MouseButton1Down:Connect(function()
if not CooldownButton then
if not IsPurchased then
CooldownButton = true
wait(1)
EquipTrailRE:FireServer(FrameC.Name)
print("This is a TextButton")
CooldownButton = false
else
end
end
FULL CODE HERE
Quick look at your code and from what I can see, it creates the MouseButton1Down event for how many objects are in the UIFolder on the same button. So you may need to change your code to fix that around.
What exactly are you trying to do?
You are attaching a new MouseButton1Click and MouseButton1Down every client event to the buttons. All connections are then fired when you click. Not sure what you are trying to do but an easy way will be to store the connections in some sort of table or variable and reset it every time like shown:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LocalPlayer = Players.LocalPlayer
local TrailFolder = LocalPlayer:WaitForChild("Trails")
local ScriptFolder = ReplicatedStorage:WaitForChild("Scripts", 1)
local RemoteFolder = ReplicatedStorage:WaitForChild("Remotes", 1)
local UIFolder = ReplicatedStorage:WaitForChild("UI")
local EventFolder = RemoteFolder:WaitForChild("Events")
local ArrangeTrailRE = EventFolder.ArrangeTrail
local BuyAllTrailRE = EventFolder.BuyAllTrail
local EquipTrailRE = EventFolder.EquipTrail
local PurchasedTrailRE = EventFolder.PurchasedTrail
local UnequipTrailRE = EventFolder.UnequipTrail
local Frame = script.Parent
local ScrollingFrame = Frame.ScrollingFrame
local UIGridLayout = ScrollingFrame.UIGridLayout
local SideBackground = Frame.SideBackground
local FrameC = SideBackground.Frame
local ColorTrail = FrameC.Color
local ToggleButton = SideBackground.ToggleButton
local BitsBoost = SideBackground.BitsBoost
local TrailCost = SideBackground.TrailCost
local TrailName = SideBackground.TrailName
local IndexNumber = 1
local connections = {}; -- Make a table to store connections
ArrangeTrailRE.OnClientEvent:Connect(function()
for i,v in pairs(UIFolder.Trails:GetChildren()) do
local GetFrameTrail = v:Clone()
GetFrameTrail.Parent = ScrollingFrame
GetFrameTrail.LayoutOrder = GetFrameTrail.ItemNumber.Value
UIGridLayout:ApplyLayout()
if connections["GetFrameTrailConnection"] then connections["GetFrameTrailConnection"]:Disconnect() end
connections["GetFrameTrailConnection"] = GetFrameTrail.MouseButton1Click:Connect(function()
FrameC.Name = GetFrameTrail.Name
TrailName.Text = GetFrameTrail.Name .. " Trail "
TrailCost.Text = GetFrameTrail.Cost.Value .. " Tokens "
ColorTrail.UIGradient.Color = GetFrameTrail.Color.UIGradient.Color
BitsBoost.Text = "x" .. GetFrameTrail.BitsBoost.Value .. " Bits "
local IsPurchased = TrailFolder:FindFirstChild(GetFrameTrail.Name)
if IsPurchased then
ToggleButton.Text = "EQUIP"
else
ToggleButton.Text = "BUY"
end
end)
local IsPurchased = TrailFolder:FindFirstChild(FrameC.Name)
local CooldownButton = false
if connections["ToggleButtonConnection"] then connections["ToggleButtonConnection"]:Disconnect() end
connections["ToggleButtonConnection"] = ToggleButton.MouseButton1Down:Connect(function()
if not CooldownButton then
if not IsPurchased then
CooldownButton = true
wait(1)
EquipTrailRE:FireServer(FrameC.Name)
print("This is a TextButton")
CooldownButton = false
else
end
end
end)
end
end)
local IsPurchased = TrailFolder:FindFirstChild(FrameC.Name)
local CooldownButton = false
ToggleButton.MouseButton1Down:Connect(function()
if not CooldownButton then
wait(1)
CooldownButton = true
if not IsPurchased then
EquipTrailRE:FireServer(FrameC.Name)
print("This is a TextButton")
CooldownButton = false
else
print("error")
end
end