Greeting, i’m having trouble with an error in my script where if i push 1 button, the Gui will pop up and not wait for the other button’s to be clicked. However, i want to have multiple button’s to make a Gui pop up when all button’s are clicked.
Here’s the code:
Axe = game.Workspace.Scripts.Block_click_axe.Block_click.ClickDetector
Bone = game.Workspace.Scripts.Block_click_bone.Block_click.ClickDetector
Pin = game.Workspace.Scripts.Block_click_pin.Block_click.ClickDetector
Spider = game.Workspace.Scripts.Block_click_spider.Block_click.ClickDetector
Cheese = game.Workspace.Scripts.MovingBlock_5.Block.ClickDetector
function onClicked()
if ("Axe" and "Bone" and "Pin" and "Spider" and "Cheese") then
script.Parent.TextTransparency = "0"
else
print("Error, can't find Axe, Bone, Pin, Spider, or,Cheese.")
end
end
game.Workspace.Scripts.Block_click_spider.Block_click.ClickDetector.MouseClick:connect(onClicked)
game.Workspace.Scripts.Block_click_pin.Block_click.ClickDetector.MouseClick:connect(onClicked)
game.Workspace.Scripts.MovingBlock_5.Block.ClickDetector.MouseClick:connect(onClicked)
game.Workspace.Scripts.Block_click_axe.Block_click.ClickDetector.MouseClick:connect(onClicked)
game.Workspace.Scripts.Block_click_bone.Block_click.ClickDetector.MouseClick:connect(onClicked)
(This is my first post, and i’m not the best at scripting. Thank you for your time.)
You’re going to need to store data and record for every single button when each one is clicked. Then when each one is clicked, you can check if the rest of them are clicked, and if so, open the GUI.
Also, something to note: when you use strings in a conditional, they always equate to true unless they’re empty.
if "literally anything" then
print("This will always print")
end
That’s why the conditional you had in your OnClick() function was always true.
Bone = game.Workspace.Scripts.Block_click_bone.Block_click.ClickDetector
Pin = game.Workspace.Scripts.Block_click_pin.Block_click.ClickDetector
Spider = game.Workspace.Scripts.Block_click_spider.Block_click.ClickDetector
Cheese = game.Workspace.Scripts.MovingBlock_5.Block.ClickDetector
data = {}
function check()
print(#data)
if #data == 5 then
print("All clickdetectors have been clicked")
script.Parent.TextTransparency = 0
end
end
game.Workspace.Scripts:FindFirstChild("Block_click_spider"):FindFirstChild("Block_click").ClickDetector.MouseClick:connect(function()
if table.find(data,"Axe") then
else
table.insert(data,"Axe")
check()
end
end)
game.Workspace.Scripts:FindFirstChild("Block_click_pin"):FindFirstChild("Block_click").ClickDetector.MouseClick:connect(function()
if table.find(data,"Bone") then
else
table.insert(data,"Bone")
check()
end
end)
game.Workspace.Scripts:FindFirstChild("MovingBlock_5"):FindFirstChild("Block").ClickDetector.MouseClick:connect(function()
if table.find(data,"Pin") then
else
table.insert(data,"Pin")
check()
end
end)
game.Workspace.Scripts:FindFirstChild("Block_click_axe"):FindFirstChild("Block_click").ClickDetector.MouseClick:connect(function()
if table.find(data,"Spider") then
else
table.insert(data,"Spider")
check()
end
end)
game.Workspace.Scripts:FindFirstChild("Block_click_bone"):FindFirstChild("Block_click").ClickDetector.MouseClick:connect(function()
if table.find(data,"Cheese") then
else
table.insert(data,"Cheese")
check()
end
end)```