I try to use for everytime, but I want to learn to use the while loop.Everytime I try t, it glitches the debounce.Any help?
function pizza(mouse) if debounce == false then debounce = true local x = Instance.new("Part") x.Shape = "Ball" x.CanCollide = false x.TopSurface = "Smooth" x.BottomSurface = "Smooth" x.Transparency = 0.7 x.Parent = Workspace x.Size = Vector3.new(10, 10, 10) x.Name = Player.Name x.BrickColor = BrickColor.new("Black") game.Debris:AddItem(x, 10) y = Instance.new("BodyVelocity") y.maxForce = Vector3.new(math.huge, math.huge, math.huge) y.velocity = Player.Character.Torso.CFrame.lookVector*160 x.Parent = Workspace y.Parent = x f = Instance.new("Fire", x) f.Heat = 0 f.Size = 30 x.CFrame = Player.Character.Torso.CFrame*CFrame.new(0, 0, -10) while x do wait(0.1) x.Size = x.Size+Vector3.new(10, 10, 10) end wait(1) debounce = false end end
I can use the tool just once, then the debounce go infi.I think it's because x is true yet, even tho it should last 10 seconds.
Your variable x
is pointing to the memory location of the x
part. Even though you add it to debris and it is 'removed' the memory location still exists. My suggestion is to use a for loop or check to see if x ~= nil
.
So either change while x do
to while x ~= nil do
or replace the whole while block with:
for i = 1,100 do -- Repeat 100 times since 0.1 * 100 = 10 wait(0.1) if x == nil return break end -- Stop the loop if x does not exist x.Size = x.Size + Vector3.new(10,10,10) end
Note: The for loop is more efficient.