If you test the game, you can see that the sparkles move to 4 different corners, rather than in a circular spread.
How would I randomly spread the Sparkles in a circular spread?
Here’s how I’ve modified your function. Each particle calculates a random angle between 0 and 360 degrees and a random amount to move between min and max as a percent of the screen width.
local ts = game:GetService("TweenService")
local info = TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
+ local absoluteSize = script.Parent.AbsoluteSize
+ local aspectRatio = absoluteSize.X / absoluteSize.Y
function firework(amount)
local min = 150
local max = 250
local rX = math.random(0, 1000)/1000
local rY = math.random(0, 1000)/1000
local light = script.Light:Clone()
light.Parent = script.Parent.Area
light.Position = UDim2.new(rX,0,rY,0)
spawn(function()
local tween = ts:Create(light, info, {ImageTransparency = 1})
tween:Play()
end)
for i = 1,amount do
spawn(function()
local spark = script.Sparkle:Clone()
spark.Parent = script.Parent.Area
spark.Position = UDim2.new(rX,0,rY,0)
+ local angle = math.rad(math.random(0, 360))
+ local mag = math.random(min, max) / 1000
+ local newPos = UDim2.new(rX + math.cos(angle) * mag, 0, rY + aspectRatio * math.sin(angle) * mag, 0)
spark:TweenPosition(newPos, "InOut", "Quad", .5, true)
wait(.6)
local tween = ts:Create(spark, info, {ImageTransparency = 1})
tween:Play()
end)
end
end
wait(5)
for i = 1,1 do
spawn(function() firework(25) end)
wait(.5)
end