Changing a dummy's position using mouse.hit

I’m trying to make a script that changes a dummy’s position depending on where your mouse is at

local button = script.Parent.TextButton
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local dummy = game.ReplicatedStorage:WaitForChild("Minigun"):Clone()

button.MouseButton1Up:Connect(function()
	print("button pressed")
	dummy.Parent = game.Workspace
	mouse.TargetFilter = dummy
	while true do
		local pos = mouse.Hit.Position
		dummy.HumanoidRootPart.Position = pos
		wait()
	end
end)

the problem is, changing the position of dummy’s humanoid root part does not move the entire body and I can’t think of an alternative way.

You use :SetPrimaryPartCFrame() and make sure the CFrame is CFrame.new(pos)

Can you tell me how I can implement :SetPrimaryPartCFrame() in my script?

Sure! So basically, wherever you would set the dummy’s HumanoidRootPart’s position, it wouldn’t move the character, just the RootPart. SetPrimaryPartCFrame() moves the entire character, based on the position of the HumanoidRootPart. The line:

dummy.HumanoidRootPart.Position = pos

can be changed to:

dummy:SetPrimaryPartCFrame(CFrame.new(pos))

If you are inexperienced with them, I suggest reading up on CFrames here.

1 Like

Oh, I get it now, thanks for the help