How do I make a part appear in a random spot within a part

Basically, I’m making a smoke particle but its blocky and 3D.
I want the smoke part to appear randomly within the smoke emitter
I am not using a particle emitter.
Code:

while true do
local smoke = Instance.new("Part")
smoke.Size = Vector3.new(0.4,0.4,0.4)
smoke.Position=--im stumped here
smoke.Parent=script.Parent
smoke.Transparency=0.5
smoke.BrickColor=BrickColor.new("Lily white")
smoke.Anchored=true
local smokeup = script.script:Clone()
smokeup.Parent = smoke
smokeup.Disabled=false
wait(3)
end

Why aren’t you using a Particle Emitter? It would make it less laggy, Less work and less buggy.

The theme of my game is 8-bit and its supposed to be 3D.

Usually youd just get a random number between:

part.Position-part.Size/2
And
part.Position+part.Size/2

On the X, Y and Z axes

uhh i got a bit of an issue

smoke.Position = script.Parent.Position-script.Parent.Size/2 script.Parent.Position+script.Parent.Size/2

how do i put both the + and - together

I would save them separately and math.random it all together in a vector3

local min = pos-size/2
local max = pos+size/2
smoke.Position = Vector3.new(
    math.random(min.X,max.X),
    math.random(min.Y,max.Y),
    math.random(min.Z,max.Z)
)
1 Like