Hi, so I'm trying to make an automatic ball spawner at a certain position when the bricked is clicked, and after the brick is clicked twice the script is disabled. The ball for some reason isn't spawning, but it is printing Hi to show that the clicking is working. Is there something wrong with the cloning? Please help, I tried almost everything.
head = game.Workspace.corner.PRESS_ME.Head clicked = false head.ClickDetector.MouseClick:connect(function() print("HI") if click == false then click = true while click == true do local BC = game.Lighting.Basketball:Clone() BC.Parent = game.Workspace.corner.Spawner BC.Handle.Position = Vector3.new(-7.8, 14.2, 31.6) wait(5) end end end) head.ClickDetector.MouseClick:connect(function() if click == true then click = false end end)
Take out the while loop, keep the debounce. After it is clicked, make click true, then wait until that wait(5) past, then make click false again. Try that.
You have:
if click == false then click = true while click == true do
First off, I dont understand why you have "while click == true do" simply put, the loop will never end. You turned it to true before entering the loop, and you have no way out. at the end of the code, in line 13, add something like this:
click = false
That means that the clone will be first put in, and then once it is in every time the thing is clicked, it will be teleported back to the first spot. I dont see the point of the code at line 20-24. If you wanted it to work only twice, then you'll have to change it up a bit.
head.ClickDetector.MouseClick:connect(function() if click == false then click = true if click == true then local BC = game.Lighting.Basketball:Clone() BC.Parent = game.Workspace.corner.Spawner BC.Handle.Position = Vector3.new(-7.8, 14.2, 31.6) click=false wait(5) head.ClickDetector.MouseClick:connect(function() if click ==false then click = true if click == true then BC.Handle.Position = Vector3.new(-7.8, 14.2, 31.6)
Remember to add the ends at the end. Try this if you want, no garentee it'll work this is simply what I would try(Though I'm obviously not the best at this site)