Help on making items spawn above a invisible part

Hey! so im making some sort of survival game and im making items spawning on invisible parts, and i want to make it so whenever the part spawns it will spawn above the invisible part (the size of the invisible part is 1,1,1) and they need to spawn like laying above the invisible part, heres an image to describe how it should be:

Screenshot_180

But instead they are spawning floating like this:

Screenshot_181

Heres the script (and also the invisible part is turned so the items spawn laying above it at the right orientation)

itemfolder = game.ReplicatedStorage.faketools:GetChildren()
local item = itemfolder[math.random(math.max(#itemfolder, 1))]:Clone()
workspace.Part.Size = item.Size
item.Parent = workspace.Part
item.CFrame = workspace.Part.CFrame + Vector3.new(0,item.Size.Y, 0) 

Thanks so much im advance im having a loooot of problems with this :slight_smile:

1 Like
itemfolder = game.ReplicatedStorage.faketools:GetChildren()
local item = itemfolder[math.random(math.max(#itemfolder, 1))]:Clone()
workspace.Part.Size = item.Size
item.Parent = workspace.Part
item.CFrame = workspace.Part.CFrame + Vector3.new(0,item.Size.Y+1, 0)

Try adding 1 to the item’s size (to the position)!

1 Like

item.CFrame = workspace.Part.CFrame + Vector3.new(0, 0.5 + item.Size.Y / 2, 0)

1 Like

Almost complete!

item.CFrame = spawnPart.CFrame+Vector3.new(0,(spawnPart.Size.Y/2)+(item.Size.Y/2),0)

This code will adapt to any size that the spawnPart may have. :slight_smile:

This helped but its stil 0.25 studs above, thats kinda weird

i tried this but now the part is floating even more above the ground rip

Go check the CFrame of your item. The CFrame might be larger than what the item looks like. :slight_smile:

Wdym by checking the cframe? every item is the exact size of the mesh it just rotates to the cframe of the spawn part, maybe use different angles to go up?

There’s the problem.

You can’t take Item.Size.Y if you’re rotating the part. :slight_smile:

Because let’s say you have a part that is (1,4,1), but you rotate it so it lays down. Then it looks like it’s (1,1,4) but it is still in fact (1,4,1)

And then if you tell the script to offset the item by item.size.y/2+spawnPart.size.y/2, then the part will be 2.5 studs above the spawnPart (or something like that)

1 Like

I was thinking about it tho is it a problem? bc if it is then how will i make it rotate like if its laying down? (simulating someone put it in there (also like piggy intercity for an example))

I would suggest only rotating the itemMesh, and then have a ParentPart that holds the itemMesh, that isn’t rotated. :slight_smile:

like a part with 1,1,1 in its size parented to the mesh?

what about checking bounding box tho

1 Like

Like a 1,1,1 being the parent of the itemMesh, so the itemMesh is inside the ParentPart.

You mean Model:GetExtentsSize()?

what is the bounding box?
30-characters

model:getboundingbox for getting model height
the blue thing you see in studio

ohhh i think that would actually work! i will try that but before i will see what one beets is trying to say

So basically the same I assume?

itemfolder = game.ReplicatedStorage.faketools:GetChildren()
local item = itemfolder[math.random(math.max(#itemfolder, 1))]:Clone()
workspace.Part.Size = item.Size
item.Parent = workspace.Part
item:SetPrimaryPartCFrame(workspace.Part.CFrame + Vector3.new(0, 1, 0))