I am trying to make a system when all the buttons are invisible you get a tool. I tried several times to fix it, but it doesnt work. Can anyone help me
local Buttons = script.Parent.Frame.Frame
local Cup = game.ReplicatedStorage.Boba.Cup
local Player = game.Players.LocalPlayer
if Buttons.Button1.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button2.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button3.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button4.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button5.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button6.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button7.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button8.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button9.TextButton_Roundify_12px.ImageTransparency == 1 then
print("Event fired")
local CupClone = Cup:Clone()
CupClone.Parent = Player.Backpack
print("Gave "..Player.Name.." the tool")
script.Parent.Enabled = false
end
Maybe add it to a while loop of some sort? Since its not looped its not repeating to wait if that works.
While Wait() do
if Buttons.Button1.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button2.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button3.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button4.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button5.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button6.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button7.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button8.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button9.TextButton_Roundify_12px.ImageTransparency == 1 then
print("Event fired")
local CupClone = Cup:Clone()
CupClone.Parent = Player.Backpack
print("Gave "..Player.Name.." the tool")
script.Parent.Enabled = false
end
end
local hasTool = false
While Wait() do
if hasTool == false then
if Buttons.Button1.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button2.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button3.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button4.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button5.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button6.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button7.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button8.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button9.TextButton_Roundify_12px.ImageTransparency == 1 then
print("Event fired")
local CupClone = Cup:Clone()
CupClone.Parent = Player.Backpack
print("Gave "..Player.Name.." the tool")
script.Parent.Enabled = false
hasTool = true
end
end
end
The problem you have is that the code only runs once, you want to continuously check it in the loop, and once you are given the tool you break the loop to avoid it getting spammed into your inventory.
Use the GetPropertyChangedSignal function to detect when a certain property changes its value, it’s more efficient than encasing it in a loop
local Buttons = script.Parent.Frame.Frame
local Cup = game.ReplicatedStorage.Boba.Cup
local Player = game.Players.LocalPlayer
Buttons.Button1.TextButton_Roundify_12px:GetPropertyChangedSignal("ImageTransparency"):Connect(function()
if Buttons.Button1.TextButton_Roundify_12px.ImageTransparency == 1 and
Buttons.Button2.TextButton_Roundify_12px.ImageTransparency == 1 and
Buttons.Button3.TextButton_Roundify_12px.ImageTransparency == 1 and
Buttons.Button4.TextButton_Roundify_12px.ImageTransparency == 1 and
Buttons.Button5.TextButton_Roundify_12px.ImageTransparency == 1 and
Buttons.Button6.TextButton_Roundify_12px.ImageTransparency == 1 and
Buttons.Button7.TextButton_Roundify_12px.ImageTransparency == 1 and Buttons.Button8.TextButton_Roundify_12px.ImageTransparency == 1 and
Buttons.Button9.TextButton_Roundify_12px.ImageTransparency == 1 then
print("Event fired")
local CupClone = Cup:Clone()
CupClone.Parent = Player.Backpack
print("Gave "..Player.Name.." the tool")
script.Parent.Enabled = false
end
end)
I JUST REALIZED THE AMOUNT OF DARN IMAGELABELS HOLY MACERONI
Another thing you should do is create an array with all the buttons you want to check, and loop through that and see if each one is invisible before continuing, would be much more efficient than writing a hundred and operators.
local Buttons = script.Parent.Frame.Frame
local Connections = {}
local Cup = game.ReplicatedStorage.Boba.Cup
local Player = game.Players.LocalPlayer
local BUTTON_COUNT = 9
local function Check()
local Count = 0
for i = 1,9 do
Count += Buttons["Button"..i].TextButton_Roundify_12px.ImageTransparency
end
return Count == BUTTON_COUNT
end
for i = 1,9 do
local Btn = Buttons["Button"..i].TextButton_Roundify_12px.ImageTransparency
table.insert(Connections, Btn:GetPropertyChangedSignal("Transparency"):Connect(function()
if Check() then
local CupClone = Cup:Clone()
CupClone.Parent = Player.Backpack
script.Parent.Enabled = false
for i,v in pairs(Connections) do
v:Disconnect()
end
end
end))
end
if it doesnt work or you need any help just let me know, i havent tested it