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

Why do parts follow my mouse when I when I click it but not a model?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mtarget
local down



function clickObj()
	if mouse.Target ~= nil and mouse.Target.Name == "model" then
		mtarget = mouse.Target
		print(mtarget)
		mouse.TargetFilter = mtarget
		print(mouse.TargetFilter)
		down = true
	end
end
mouse.Button1Down:connect(clickObj)


function mouseMove()
	if down and mtarget then
		local posX,posY,posZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.z
		
		mtarget.Position = Vector3.new(posX,posY,posZ)
	end
end
mouse.Move:connect(mouseMove)


function mouseDown()
	down = false
	mouse.Target = nil
	mouse.TargetFilter = nil
end
mouse.Button1Up.connect(mouseDown)

1 answer

✓ Accepted answer

The Model class does not have a Position value

you would have to use the function Model:MoveTo()

also use ClassName instead of name when checking for models so you don't have to to name all of your models "model"

also use :Connect() not :connect()

fixed version should look like this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local mtarget
local down



function clickObj()
    if mouse.Target ~= nil and mouse.Target.Parent.ClassName == "Model" then -- Changed name to ClassName
        mtarget = mouse.Target.Parent
        print(mtarget)
        mouse.TargetFilter = mtarget
        print(mouse.TargetFilter)
        down = true
    end
end
mouse.Button1Down:Connect(clickObj)


function mouseMove()
    if down and mtarget then
        local posX,posY,posZ = mouse.Hit.X,mouse.Hit.Y,mouse.Hit.z

        mtarget:MoveTo(Vector3.new(posX,posY,posZ)) -- Added the function
    end
end
mouse.Move:connect(mouseMove)


function mouseDown()
    down = false
    mtarget = nil
    mouse.TargetFilter = nil
end
mouse.Button1Up:Connect(mouseDown)

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