Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED]How to make both parts in a model move together using "mouse.Hit.p"?

So, i'm trying to make a building system. I want models with multiple parts to move together .

But my outcome ends up with one part in the correct position(although slightly clipped into the ground).

SCREENSHOTS

My Model

My model hierarchy

My tool hierarchy

What happens

SCRIPT

-- May add a remove event for server side soon.


local test = game:GetService("ReplicatedStorage").Buildings.Test -- My Building
local tool = script.Parent -- Get the Tools
local db = false -- Debounce
local mouse = game:GetService("Players").LocalPlayer:GetMouse()

tool.Activated:Connect(function()
	if db == false then
		db = true
		local building = test:Clone() -- Clone it
		building.Parent = workspace
		
		local position = mouse.Hit.p -- Calculate the position
		
		building.PrimaryPart.Position = position -- Using PrimaryPart, because i thought it would work with multiple parts
		
		wait(1)
		
		db = false
		
	end
end)


(fyi im not a good scripter at this kind of stuff, ok?)

4 comments

1

You use MoveTo to move a model to a certain position however, MoveTo moves the object up on the Y axis if there is anything in the way of the model you are moving

0

If you want it to not account for objects in the way, you can use SetPrimaryPartCFrame, and provide a CFrame value as opposed to a Vector3

0

I'll try using "MoveTo"

0

"MoveTo" works, yay!

1 answer

Alright, multiple problems. your first issue is that to move an entire model, you have to cframe it instead of setting a position. AKA instead of building.PrimaryPart.Position = position do building.PrimaryPart.CFrame = CFrame.New(position). Second, to unclip it from the ground you need to add half the height of the model, so just add change it to local position = mouse.Hit.p+Vector3.new(0,building:GetExtentsSize.y/2,0). Also this one is too big for me to solve, but if this is a localscript then it wont actually place, it'll only look like it did to that one player. Basically look at https://developer.roblox.com/en-us/articles/Roblox-Client-Server-Model

3 comments

0

I get this error: "Workspace.BashGuy10.Build.LocalScript:15: function arguments expected near '.'" when using your answer

0

Also, i tried adding parentheses to the end. it still didn't work, it ended up like the problem i have.

0

You probably just accidentally copied a period lol. Just look for any dots on the end with nothing after them

This discussion is preserved as it was. New answers, comments, and votes are closed.