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

Button won't spawn a car if there already is one, even though it should? [Solved]

Asked by
pwnd64 106
8 years ago

Hi, I'm trying to make a clickable button that will respawn a car when you click on it.

Edit: The problem was that it was spawning one every time it saw that a car was far enough away.

Button = script.Parent.ClickDetector

Debounce = true

Spawnable = true

Button.MouseClick:connect(function()

    if Debounce == true then

        Debounce = false

    for i,v in pairs(workspace:GetChildren()) do

        if v.Name == "Car" or v.Name == "Car2" or v.Name == "Car3" then

            if v.Name == "Car" and (v.VehicleSeat.Position - Button.Parent.Position).magnitude > 20 then

                Spawnable = true

            elseif (v.VehicleSeat.Position - Button.Parent.Position).magnitude <= 20 then

                Spawnable = false               

                break

            end

        end         

    end

    if not workspace:FindFirstChild("Car") then

        Spawnable = true

    end

    if Spawnable == true then

        game.ReplicatedStorage.Car:Clone().Parent = workspace

        Spawnable = false

        Button.Parent.BrickColor = BrickColor.new("Black")

    end

    wait(2) 

    Debounce = true

    Button.Parent.BrickColor = BrickColor.new("Lavender")

    end

end)

Thanks

0
I would suggest you delete this question or answer it yourself and click accept, Just putting solved doesn't cut it. Conmmander 479 — 8y
0
alright pwnd64 106 — 8y

Answer this question