So as I was trying to add items to build, I had came to realize that since all of my build items were models(well most of them) it has resulted in an error where the model doesn’t have a property called position. After seeing this error, I knew how to solve it but after I added that for loop in, the script was not working how it should be. I know what the problem is however, I don’t know how to fix it.
robloxapp-20210612-1137543.wmv (552.2 KB)
for i,v in pairs(BuildItems[f]:GetChildren()) do
if v:IsA("Part") or v:IsA("UnionOperation") then
v.Position = mouse.Hit.Position
v.Parent = workspace
By looping through every part and setting their position to the mouse’s position, you’re not maintaining the structure of the model and you’re just blobbing every part in to one position. A good way to move a model and maintain its shape is to use a primary part with the function
I reccommend watching this video so you can properly understand how to set up the primary part.
So you can just make an invisible primary part in the center of the model and then use something like this
BuildItems[f].Parent = workspace
On another note, you might want to research RemoteEvents, as the script you’re using right now will only move the model for the person who clicked. Others won’t be able to see it because it was all done on the client instead of the server, and there is a boundary preventing localscripts from showing game changes to other players. This is done to combat exploiters, but means you have to do some extra steps to make this model movement show up for every other player ingame.
@exp_lol123 you can easily move a model by having one primarypart(anchored) with the rest of the other parts(unanchored) welded onto the primarypart. doing so will allow you to change the position of the ENTIRE model by simply changing the CFrame of the primarypart
It would take FOREVER to add a weld constraint or even paste it since when you paste it, the part 0 will be the part you pasted it from. Is there a quicker way to do so?
It’s as @Rietria said: set a PrimaryPart for the model and then use
SetPrimaryPartCFrame() whenever you want to move the model. You don’t need to create a weld for every single part. Make sure all parts are anchored.
Here’s a quicker way @exp_lol123
local primaryPart = model.PrimaryPart
for _, part in pairs(model:GetChildren()) do
if part == primaryPart then return end
local x = Instance.new("Weld")
x.Part0 = primaryPart
x.Part1 = part
x.C0 = x.Part0.CFrame:Inverse()
x.C1 = x.Part1.CFrame:Inverse()
x.Parent = part
There’s something wrong with the welding.
robloxapp-20210612-1717375.wmv (552.3 KB)
Here’s the error I keep getting:
Change mouse.Hit.Position to just mouse.Hit.
Wait, for which of my bugs, the one where there’s something wrong with the welding?
I think you can click on your icon in the top right of my post to see exactly which one I replied to. I am referring in this case to
Unable to cast Vector3 to CoordinateFrame
Also, after you try that, and if it works but you want to strip rotation: