the title might be confusing, but I’ll explain what’s happening.
I have these berry spawns, that spawn berries in random positions that can be collected. but once every minute, a special berry called a ‘doubleberry’ spawns in a random field, in a random position.
the double berry is spawning above the regular berries, rather than at the same height as them, but if the doubleberry isn’t touching any other berries, it will spawn at the same height.
none of the berries (including the doubleberry) have collisions on. I’m not really sure what to do, I tried moving it 10 studs above, then moving it down again, but it didn’t work.
I also tried setting the position of the berry before parenting it to workspace, but that didn’t work either. here’s the code if you need it.
local Field = workspace.Fields[math.random(1,#workspace.Fields:GetChildren())]
print(Field.name.Value) -- forgot to remove this
local field = workspace.Fields[Field.Name]
local start = field.One
local End = field.Two
local new = doubleberry:Clone()
local XPos = math.random(start.Position.X, End.Position.X)
local ZPos = math.random(start.Position.Z, End.Position.Z)
new.Parent = field.Gems
new:MoveTo(Vector3.new(XPos, field.One.Position.Y +3, ZPos))
The MoveTo function’s behavior allows itself to not clip with other objects, thus always spawns above anything that intersects with its position that was set initially.
Hmmm, no, but there is another solution that would be considered better. You can try set a PrimaryPart on the object and then using SetPrimaryPartCFrame function on the model to move the entire model.
local Field = workspace.Fields[math.random(#workspace.Fields:GetChildren())]
print(Field.name.Value) -- forgot to remove this
local field = workspace.Fields[Field.Name]
local start = field.One
local End = field.Two
local new = doubleberry:Clone()
local XPos = math.random(start.Position.X, End.Position.X)
local ZPos = math.random(start.Position.Z, End.Position.Z)
-- new.PrimaryPart = new:GetChildren()[math.random(#new:GetChildren())]
new:SetPrimaryPartCFrame(CFrame.new(XPos, field.One.Position.Y +3, ZPos))
new.Parent = field.Gems
actually it turns out I’m dumb, lol. I made a mistake when changing the functions, and forgot to remove something that was there. :SetPrimaryPartCFrame() works perfectly. Thank you!