First off, sorry if the title was a little confusing, I don’t know how to explain my problem well.
Essentially, I have a script that spawns parts inside of a square and moves them in one direction.
local RunService = game:GetService("RunService")
local Spawner = script.Parent
local Rand = Random.new()
local Rate = 25 -- per second
local Length = 8 -- studs
local Speed = 20 -- stud per second
local Lifetime = 5 -- seconds
local Thickness = 0.2 -- studs
local XSize = Spawner.Size.X
local YSize = Spawner.Size.Y
local Parts = {}
local function SpawnPart()
local p = Instance.new("Part", workspace)
local posoffset = (Spawner.CFrame.UpVector * Rand:NextNumber(YSize/2,-YSize/2)) + (Spawner.CFrame.RightVector * Rand:NextNumber(XSize/2,-XSize/2))
p.Anchored = true
p.CFrame = Spawner.CFrame + posoffset
p.Size = Vector3.new(Thickness,Thickness,Length)
return p
end
local b = 0
RunService.Heartbeat:Connect(function(t)
for i,v in pairs(Parts) do
v.CFrame += v.CFrame.LookVector * (t * Speed)
end
end)
while true do
Parts[#Parts + 1] = SpawnPart()
wait(1/Rate)
end
I want the part spawning to neglect an area inside of the square, so that parts won’t spawn in the middle.
Thanks for the help!