Question with a script

i have a script that grabs a part with the mouse and moves it to where the mouse is moving but i want to grab a whole model to move(Multiple parts) instead of just one, here is the script:

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()

local billBoardGui = script.Parent
local imageButton = billBoardGui:WaitForChild(“ImageButton”)

local runService = game:GetService(“RunService”)
local isMoving = false

local movePart

local part = billBoardGui.Adornee

if not isMoving then isMoving = true
	movePart = runService.RenderStepped:Connect(function()
		mouse.TargetFilter = part 
		part.Position = mouse.Hit.Position
	end)
else
	movePart:Disconnect()
	mouse.TargetFilter = nil
	isMoving = false

end

USI = game:GetService(“UserInputService”)

USI.InputBegan:Connect(function(input)
if isMoving == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
script:Destroy()
end
end
end)

You need to make use of WeldConstraints to weld all the other parts to the PrimaryPart of the model.
See more here:

1 Like

i did that but it moves just the part alone

I think you might’ve welded it wrong, you need to click the primary part first, and then the other parts. The way it is right now, it may be that the other parts cause your primary part to move, but the primary part can’t cause the other parts to move.

1 Like

set its CFrame, not position

part.CFrame = CFrame.new(mouse.Hit.Position)

or another way since its a model;

model:PivotTo(CFrame.new(mouse.Hit.Position))

just tried it again its not working:/

did that, it grabbed the whole thing but its moving a bit weird, the model is moving towards the invert direction that im looking and it rotated 90 degrees

mitigate it by multiplying the mouse position with an angle,

local newpos = CFrame.new(Mouse.Hit.Position)*CFrame.Angles(math.rad(90),0,0)

part.CFrame = newpos
--or
model:PivotTo(newpos)

play around with the axis x y z adding a certain degree

it worked now, thank you so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.