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?>
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
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)