Help on making items spawn above a invisible part

Hi! this won’t work. Please read through our replies. :slight_smile:

Edit: Or was I too quick to judge? Might be the +1 in vector that throws me off.

“Help on making items spawn above a invisible part” Setting the primarypartcframe should work just fine for this.

This works with some items but wouldnt work with every item bc some have different heights

We’ve already posted a few approaches for you. Happy scripting!

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, item:GetExtentsSize().Y + 1, 0))

Edit: I can’t currently open ROBLOX studio for some reason so I can’t actually test

i will try checking how i can make this and try yours and beets solutions, thanks for the help :slight_smile:

i just figured that getexentssize wont work because its a mesh part, and if i do what @TortenSkjold said then it pratically would be useless bc the part would be 1,1,1. And ima try it

1 Like

If it’s mesh then I think theres something built in for this… Scale

Pretty much just get the scale value and add a vector3 value of 0, 1, 0 onto it and I belive it should work

1 Like

i found a thread where people figured out the algorithm for calculating boundingbox
btw im pretty sure you could just calculate the y-height based on cframe but im tired so my brain wont work

check this out. i think on post 7 theres a solution for boundingbox on part or model

1 Like

Hi! I think I cracked a solution in my head for you! :slight_smile:

Pivotpoints!

Make your item face in the direction you want, edit it’s pivotPoint so that the pivot is at the “bottom” of the part. - Just make sure your Pivot is rotated and placed correctly.

Now, make so that your ItemSpawner’s PivotPoint is at the very top of the ItemSpawner.

Now just do

ItemPart:PivotTo(ItemSpawner:GetPivot())

That will set the ItemPart’s Pivot to be in the location of the ItemSpawner’s Pivot.
I tend to tell people to use PivotPoints more often, and this is a good example on why.

1 Like

Please let us know which approach you went with, when you’ve solved your issue! :slight_smile:

1 Like

hi, maybe try to use the up vector value of the part like this:

local Item = workspace.MyItem

local formatCF = workspace.Cubepart.CFrame + (workspace.Cubepart.CFrame.Position.LookVector) * 0.5 --The distance above the part in studs

Item:SetPrimaryPartCFrame(formatCF)
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/2, 0) 

may be this would work

1 Like

This have already been suggested, and it would not work when the Item have been rotated to lay down. :slight_smile:

1 Like

i tried this but it got an error saying that LookVector isnt a valid member of Vector3

Ohhh that actually seems like its going to work, but how do i see the pivot point?
WAIT i figured it out and IT WORKS PERFECTLY! tysm! :slight_smile:

Great that you found a solution, happy scripting!