The button system I am working on has an issue, which I have tried to fix, but I can not seem to find a fix for it
the problem is, when a plot is claimed the buttons are to become visible, as shown in the script below
local Connection
Connection = value.OwnerValue.Changed:Connect(function(updatedValue)
if updatedValue ~= nil then
print("updated")
for _, v in pairs(Buttons:GetChildren()) do
print("looped throuh buttons")
if not v:FindFirstChild("Dependency") then
-- The script does not enter this part
print(v.Name .. " is not dependent on anything")
local bpart = v:FindFirstChildWhichIsA("BasePart")
v.ButtonPart.Transparency = 0
bpart.CanCollide = true
bpart.CanTouch = true
bpart.BillboardGui.Enabled = true
bpart.BillboardGui.Frame.TextLabel.Text = " "..v.Name.." $"..v.Price.Value.." "
end
end
Connection:Disconnect()
end
end)
I would love to know why it isn,t working?, and how to fix it.
I would also love to know if there is a better way, to write out that part of the script
Here is the full script of the button system Down below
local ButtonsModule = {}
local tycoons = game.Workspace.Tycoons:GetChildren()
local objects = {}
local debounce = {}
local function Check()
for _, t in pairs(tycoons) do
local Buttons = t:FindFirstChild("Buttons")
local purchaseditems = t:FindFirstChild("PurchasedItems")
for _, v in pairs(Buttons:GetChildren()) do
local depend = v:FindFirstChild("Dependency")
if depend and purchaseditems:FindFirstChild(depend.Value) then
local bpart = v:FindFirstChildWhichIsA("BasePart")
bpart.Transparency = 0
bpart.CanCollide = true
bpart.CanTouch = true
bpart.BillboardGui.Enabled = true
bpart.BillboardGui.Frame.TextLabel.Text = " "..v.Name.." $"..v.Price.Value.." "
end
end
end
end
function ButtonsModule.ButtonExecutioner()
for _, t in pairs(tycoons) do
local Buttons = t:FindFirstChild("Buttons")
local value = t:FindFirstChild("Values")
local purchaseditems = t:FindFirstChild("PurchasedItems")
local function Readyness()
for _, v in pairs(Buttons:GetChildren()) do
if v:IsA("Model") then
local bpart = v:FindFirstChildWhichIsA("BasePart")
if bpart then
bpart.Transparency = 1
bpart.CanCollide = false
bpart.CanTouch = false
bpart.BillboardGui.Enabled = false
end
end
task.spawn(function()
if v:FindFirstChild("ButtonPart") then
local objtobuy = purchaseditems:FindFirstChild(v.Object.Value)
if objtobuy ~= nil then
objects[objtobuy.Name] = objtobuy:Clone()
objtobuy:Destroy()
else
v:Destroy()
end
end
end)
end
local Connection
Connection = value.OwnerValue.Changed:Connect(function(updatedValue)
if updatedValue ~= nil then
print("updated")
for _, v in pairs(Buttons:GetChildren()) do
print("looped throuh buttons")
if not v:FindFirstChild("Dependency") then
print(v.Name .. " is not dependent on anything")
local bpart = v:FindFirstChildWhichIsA("BasePart")
v.ButtonPart.Transparency = 0
bpart.CanCollide = true
bpart.CanTouch = true
bpart.BillboardGui.Enabled = true
bpart.BillboardGui.Frame.TextLabel.Text = " "..v.Name.." $"..v.Price.Value.." "
end
end
Connection:Disconnect()
end
end)
--print("Name")
end
local function something()
for _, v in pairs(Buttons:GetChildren()) do
--print(v.Name)
task.spawn(function()
if v:FindFirstChild("ButtonPart") then
v.ButtonPart.Touched:Connect(function(charaterbodypart)
local player = game.Players:GetPlayerFromCharacter(charaterbodypart.Parent)
if debounce[v] then return end
debounce[v] = true
if not player then
debounce[v] = false
return
end
if player and value.OwnerValue.Value ~= player then
debounce[v] = false
return
end
if player:FindFirstChild("leaderstats").InvisibleCurrency.Cash.Value >= v.Price.Value then
v.ButtonPart.BrickColor = BrickColor.new("Gold")
player.leaderstats.InvisibleCurrency.Cash.Value -= v.Price.Value
objects[v.Object.Value].Parent = purchaseditems
v:Destroy()
Check()
else
v.ButtonPart.BrickColor = BrickColor.new("Really red")
task.wait(.7)
v.ButtonPart.BrickColor = BrickColor.new("New Yeller")
end
debounce[v] = false
end)
end
end)
end
end
Readyness()
something()
end
end
return ButtonsModule