I’m trying to make a gui shop where if you select something, it makes the button’s boolean true, and I also made a buy button on the right side that buys whatever is selected. The problem I am having is that it only works the first time, and just stops working altogether. It is not the buy button not working because I tested the select button script by printing something and it only printed the first time. I think it is the waitForSelectable function or something because when I added it, the problem started happening. Does anyone know how to fix this? Thanks,
local player = game.Players.LocalPlayer
local upgrades = player:WaitForChild("Upgrades"):GetChildren()
local whatToBuy = script.Parent.RIghtSide.WhatToBuy
local selectableBool
function waitForSelectable(Bool, Button, sBool)
while wait() do
print("wait")
if sBool.Value == true then
print("if")
Bool.Value = true
break
end
end
end
local buttons = function(Button)
Button.MouseButton1Down:Connect(function()
selectableBool = script.Parent.RIghtSide.BuyButton.SelectableBool
local otherButtons = Button.Parent.Parent:GetDescendants()
for i, v in pairs(otherButtons) do
if v:IsA("TextButton") and v.Parent.Name ~= "RIghtSide" then
v.BackgroundColor3 = Color3.fromRGB(15, 223, 255)
v.Bool.Value = false
end
end
Button.BackgroundColor3 = Color3.fromRGB(9, 135, 154)
whatToBuy.Text = Button.Text
local price
for i, upgrade in pairs(upgrades) do
if upgrade.Name == Button.Parent.Name then
local priceChild = upgrade:GetChildren()
for i, priceC in pairs(priceChild) do
price = priceC
end
end
end
whatToBuy.givePrice.Text = "Price: " .. price.Value.. " Cash"
if selectableBool.Value == true then
Button.Bool.Value = true
elseif selectableBool.Value == false then
waitForSelectable(Button.Bool, Button, selectableBool)
end
end)
end
for i,v in pairs(script.Parent:GetChildren()) do
if (v:IsA("Frame")) and v.Name ~= "RIghtSide" then
for i, vChild in pairs(v:GetChildren()) do
if vChild:IsA("TextButton") then
buttons(vChild)
end
end
end
end