You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to achieve an animation where explosion particle effects appear on random areas -
What is the issue? Include screenshots / videos if possible!
The explosions will appear far on the right of the object. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have attempted to use model bounding boxes. It worked however the explosions would sometimes be in mid air as it wasn’t accurate.
game.ServerStorage.Bindables.Explode.Event:Connect(function(object)
local ValidParts = {}
local explosions = game.ServerStorage.Particles.Explosions:GetChildren()
for i, v in pairs(object:GetDescendants()) do
if v:IsA("Part") or v:IsA("BasePart") or v:IsA("MeshPart") then
table.insert(ValidParts,v)
end
end
local x
local y
local z
local model = Instance.new("Model",object)
local function CalculateCorners(num)
local part = ValidParts[math.random(1,#ValidParts)]
local partoldparent = part.Parent
part.Parent = model
local orientation, size = model:GetBoundingBox()
local corner1 = Vector3.new(orientation.Position.X - (size.X/2),orientation.Position.Y - (size.Y/2),orientation.Position.Z - (size.Z/2))
local corner2 = Vector3.new(orientation.Position.X + (size.X/2),orientation.Position.Y + (size.Y/2),orientation.Position.Z + (size.Z/2))
part.Parent = partoldparent
if num == 1 then return corner1
elseif num == 2 then return corner2 end
end
local function DeleteParticle(particle)
wait(1)
particle:Destroy()
end
game.ServerStorage.Bindables.DeleteParticle.Event:Connect(function(particle)
wait(1)
particle:Destroy()
end)
if object:FindFirstChild("Parts"):FindFirstChild("Center") then object.Parts.Center.BodyVelocity.Velocity = Vector3.new(0,0,0) end
object.PrimaryPart:SetNetworkOwner(nil)
for i = 1,50 do --will change later once we get "nukevalue" or smth
local corner1 = CalculateCorners(1)
local corner2 = CalculateCorners(2)
if corner2.X > corner1.X then x = math.random(corner1.X,corner2.X) else
x = math.random(corner2.X,corner1.X) end
if corner2.Y > corner1.Y then x = math.random(corner1.Y,corner2.Y) else
y = math.random(corner2.Y,corner1.Y) end
if corner2.Z > corner1.Z then x = math.random(corner1.Z,corner2.Z) else
z = math.random(corner2.Z,corner1.Z) end
local particle = explosions[math.random(1,#explosions)]:Clone()
particle.Parent = game.Workspace.Projectiles
particle.Position = Vector3.new(x,y,z)
for i, v in pairs(particle:GetChildren()) do
v.Enabled = false
v:Emit(1)
end
game.ServerStorage.Bindables.DeleteParticle:Fire(particle)
wait(.25)
end
end)
Please mind anything that looks like a stupid solution, I was trying everything that came to mind.