x = 0
bu = game.Workspace.Button1
bu.ClickDetector.MouseClick:Connect(function()
x = x + 1
end)
buy1 = script.Parent
buy1.Touched:Connect(function()
if x == 5 then
buttony = game.Lighting.Button2:Clone()
buttony.Parent = game.Workspace
end
end)
The script doesn't show any errors but it's not working. I tried figuring it out and I think the problem is in the "If x == 5 then".

11 comments
have you tried changing it to if x ==5 then do, or if x==5 do?
Tried that, doesn't work
hmm
This isn't an answer to your specific problem, but I think you should work on the presentation of your code: variable names are random/abstract; It's inconsistent (Connect/connect the latter is deprecated); no logical layout - it's generally difficult to read. I'd recommend addressing this if you want to get help easier and if you want to progress further in the future. Good luck!
does the touch event run at all?
can you print out: print(x, x==5) whenever the player touches the button?
The touch event works.
The "If x == 5 then" doesn't work. When I remove the "if x == 5" it does work
Coppied your script and it worked perfectly
Really? Let me show you the game I have the script in https://www.roblox.com/games/3194043675/Game
Try printing the X variable before the if line, see if the value is actually five.