Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't the ball spawn at all when the brick is clicked?

Asked by 8 years ago

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)

2 answers

Log in to vote
0
Answered by 8 years ago

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.

Ad
Log in to vote
0
Answered by 8 years ago

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)

Answer this question