My script wont shoot out debris in random directions

Hey so my script is not doing what i want and its just picking 1 direction then shooting everything out in that direction
code:

wait(math.random(5,6))

local debris = Instance.new(“Part”)
debris.Anchored = false
debris.Size = Vector3.new(6,2.5,6)

local timeRemaining = 6

while timeRemaining > 0 do

missle = debris:Clone()
missle.Position = script.Parent.Position
missle.Parent = game.Workspace
missle.Velocity = Vector3.new(math.random(3,5),math.random(5,7),math.random(3,5))

wait(0.4)
timeRemaining = timeRemaining - 1	

end

when you change the velocity the part will quickly decelerate due to ‘technical counter forces’. This means you may set the velocity to 5 but due to the parts mass it will decelerate to Velocity(0,0,0) very quickly (could be milliseconds).

You would need to make sure it has constant velocity, this could be done by creating a bodyforce or with a script.

Edit:
There will be more ways than that, was just listening the first two I thought of.
And also what @BenMactavsin said is a great point as if you also want it to be able to shoot behind as well then then you would want negative values as well.

Switch minimum numbers in math.random()s with negative numbers.

1 Like


it worked thanks!!