So basically my models clone don’t spawn in a designated zone instead they spawn outside of it
Picture:
Full Module
local Bugss = {}
Bugss.AllBugs = game.ServerStorage.Bugs:GetChildren()
Bugss.BugZone = game.Workspace.BugZone
Bugss.BugLimit = Bugss.BugZone.BugLimit
local limit = 0
function Bugss:SpawnBug()
if #Bugss.AllBugs > 0 then
while wait() do
local Random = math.random(1, #Bugss.AllBugs)
local RandomBug = Bugss.AllBugs[Random]
local BugClone = RandomBug:Clone()
BugClone.Parent = Bugss.BugZone
local x = math.random(math.min(4, Bugss.BugZone.Position.X), math.max(4, Bugss.BugZone.Position.X))
local y = Bugss.BugZone.Position.Y +3
local z = math.random(math.min(4, Bugss.BugZone.Position.Z), math.max(4, Bugss.BugZone.Position.Z))
print("XPos: "..x,"YPos: " ..z)
BugClone:SetPrimaryPartCFrame(CFrame.lookAt(Vector3.new(x,y,z),Vector3.new(1,0,0)+Vector3.new(x,y,z),Vector3.new(1,0,0)))
limit = limit +1
print(limit)
if limit >= Bugss.BugLimit.Value then
break
end
wait(1)
end
end
end
return Bugss
Part that's Stumping me
local x = math.random(math.min(4, Bugss.BugZone.Position.X), math.max(4, Bugss.BugZone.Position.X))
local y = Bugss.BugZone.Position.Y +3
local z = math.random(math.min(4, Bugss.BugZone.Position.Z), math.max(4, Bugss.BugZone.Position.Z))
print("XPos: "..x,"YPos: " ..z)
BugClone:SetPrimaryPartCFrame(CFrame.lookAt(Vector3.new(x,y,z),Vector3.new(1,0,0)+Vector3.new(x,y,z),Vector3.new(1,0,0)))