I made a trail shop a bit ago, and today while making some changes to it, I noticed after a player buys a trail, the text changes to equip and it allows the player to wear the trail, but it charges them the price again. This probably has something to do with the Button still being connected to the buy function. I’m not sure what to do about it, because if I set a new connect function, the old one is still there
This is my code for the shop
local function SetNames()
for Index, TrailOwned in ipairs(Player.Trails:GetChildren()) do
if TrailOwned.Value then
local TrailFrame = TrailFrames[TrailOwned.Name]
local TrailButton = TrailFrame.TrailButton
local TrailName = TrailButton.TrailName
TrailName.Text = "Equip"
end
end
end
local function CheckForChanges()
--Setting up Property Changed Signal on all Trail Values
--Will Set the text of a button to equip if the player already owns the trail
for Index, Trail in ipairs(Player.Trails:GetChildren()) do
if Trail:IsA("BoolValue") then
Trail:GetPropertyChangedSignal("Value"):Connect(SetNames)
end
end
end
local function SetFunctions()
for Index, TrailOwned in ipairs(Player.Trails:GetChildren()) do
task.wait(0.1)
local TrailFrame = TrailFrames[TrailOwned.Name]
local TrailButton = TrailFrame.TrailButton
local TrailName = TrailButton.TrailName
if TrailName.Text == "Equip" then
TrailButton.MouseButton1Down:Connect(function()
EquipEvent:FireServer(TrailFrame.Name)
ClickSound:Play()
end)
elseif TrailName.Text == "Buy" then
TrailButton.MouseButton1Down:Connect(function()
if Player.leaderstats.Diamonds.Value >= TrailPrices[TrailFrame.Name] then
BuyEvent:FireServer(TrailFrame.Name, TrailPrices[TrailFrame.Name])
PurchaseSound:Play()
else
PurchaseFailedSound:Play()
end
end)
end
end
end
It basically just checks for a change in a folder attached to the player, and if there is one, it will set the name to equip.
Need help with getting rid of the player being able to buy it again while trying to equip the ttrail