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

cool down script won't work?

Asked by 4 years ago
Edited 4 years ago

Ok so I'm making a simple script where on click a part will appear infront of me, move foward, and delete after a distance. (game's like galaga). The issue is I think is it gets caught in the while/do function, disallowing the code to continue.

local cool = 0.75
local function firee()
    local bullet = Instance.new("Part")
    bullet.Parent = workspace
    bullet.Size = Vector3.new(0.75, 0.75, 1.75)
    bullet.Position = Vector3.new(root.Position.X, root.Position.Y, root.Position.Z + 4)
    bullet.Anchored = true
    while bullet do
        bullet.Position = bullet.Position + Vector3.new(0, 0, 1)
        wait(0.001)
        if bullet.Position.Z > 100 then
            bullet:Remove()
        end
    end 
end

mouse.Button1Down:Connect(function()
    if player.Character then
        if debounce then
            debounce = false
            print("Fire")
            firee()
            wait(cool)
            debounce = true
            return
        end
    end
end)

When I remove firee() from the script the print works fine but when I insert firee it breaks. I also found that if I remove the while/do function and everything inside it it works (but of course doesn't move then). Help?>

0
that variable error from formatting is really giving my mind death and im not sure why KDarren12 705 — 4y
0
sorry 'bout that, I fixed it. paperbagstudio 28 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

try this

function fire()
        local bullet = Instance.new("Part")
    bullet.Parent = game.Workspace
        bullet.Size = Vector3.new(0.75, 0.75, 1.75)
        bullet.Position = Vector3.new(root.Position.X, root.Position.Y, root.Position.Z + 4)
        bullet.Anchored = true
        if bullet then
            bullet.Position = bullet.Position + UDim2(0, 0, 1)
            wait(0.001)
            if bullet.Position.Z > 100 then
              bullet:Remove()

end
            end
        end
    end

--I believe this will fix your problem--

if this does not work i'm truly sorry i don't understand this too much

0
That made it worst, the bullet wouldn't move at all. paperbagstudio 28 — 4y
0
you need to use while bullet do, not if bullet then. Also UDim2 just bring out an error. paperbagstudio 28 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

I finally figured the answer out myself.

mouse.Button1Down:Connect(function()
    if debounce == true then
        debounce = false
        wait(cool)
        debounce = true
        return
    end
end)

mouse.Button1Down:Connect(function()
    if debounce then
        firee()
    end
end)

Answer this question