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

Why won't the fireworks disapeer?

Asked by 8 years ago

So I've made a cannon that shoots fireworks on the press of a button. It works except the fireworks won't get removed. Here's the entire script I wrote out(Lot's of copying and pasting LOL):

firework = game.ServerStorage.Firework
barrel = script.Parent.Barrel
buttonHit = false


script.Parent.Button.Touched:connect(function(hit)
    if not buttonHit then
        buttonHit = true

    local fireworkCopy = firework:Clone()
    fireworkCopy.Parent = game.Workspace
    fireworkCopy.Position = barrel.Position
    fireworkCopy.Velocity = Vector3.new(0,350,0)
    wait(2)
    fireworkCopy.Anchored = true
    fireworkCopy.F1.Enabled = true
    fireworkCopy.P1.Enabled = true
    fireworkCopy.P1.LightEmission = math.random(0.5,1)
    fireworkCopy.P1.Acceleration = math.random(1,10),-5,math.random(1,10)
    fireworkCopy.P2.Enabled = true
    fireworkCopy.P2.LightEmission = math.random(0.5,1)
    fireworkCopy.P2.Acceleration = math.random(1,10),-5,math.random(1,10)
    fireworkCopy.P3.Enabled = true
    fireworkCopy.P3.LightEmission = math.random(0.5,1)
    fireworkCopy.P3.Acceleration = math.random(1,10),-5,math.random(1,10)
    fireworkCopy.P4.Enabled = true
    fireworkCopy.P4.LightEmission = math.random(0.5,1)
    fireworkCopy.P4.Acceleration = math.random(1,10),-5,math.random(1,10)
    wait(10)
    fireworkCopy:Destroy() -- This is the code that doesn't run.

    buttonHit = false

    end
end)


For some reason, there's no error that shows up in the output. Anyone know why this happens?

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

I don't know why there's no error in the output, but I think I know what is the problem.

math.random(0.5,1) -- First of all, this doesn't make sense. When you call math.random with two parameters it chooses a whole number in between the two parameters.
--[[
math.random() with no arguments generates a real number between 0 and 1.
math.random(upper) generates integer numbers between 1 and upper.
math.random(lower, upper) generates integer numbers between lower and upper.
upper and lower **must** be integers.
]]

If you want to get a random number between .5 and 1, use the following

math.random(5,10) / 10 -- Random number between .5 and 1 (could be .5, .6, .7, .8, .9, or 1)

Also, Acceleration is a Vector3 value. Any time you are referring to a Vector3, it has to be in the following form:

Vector3.new(math.random(1,10),-5,math.random(1,10))

With Colors, BrickColors, CFrames, and UDim2's (and a few other less common ones) you will need to use a .new() when referring to them.

Ad

Answer this question