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

Why Isn't This Moving My Model To Position?

I'm trying to make it show a model in the grid that I've created when I hover over one but for some reason this is not moving the model to the correct location. Any ideas? I tried researching MoveTo but I didn't entirely understand what it was asking me to do.

local Player = game:GetService("Players").LocalPlayer;
local Mouse = Player:GetMouse();
local UIS = game:GetService("UserInputService");
local RS = game:GetService("RunService");
local curT
local Plant = game.ReplicatedStorage["Plant1"]
RS:BindToRenderStep("MouseHover", Enum.RenderPriority.Camera.Value - 1, function()
	
	local mPos = UIS:GetMouseLocation();
	
	local Target = Mouse.Target;
	
	if Target then
		if Target.Parent then
			if Target.Parent:IsA("Model") and not (Target.Parent == workspace) then
				if Target.Parent.Name == "Planter" then
					if Target ~= curT then
						print(Target.Parent.Name)
						local PlantCopy = Plant:Clone()
						PlantCopy.PrimaryPart = PlantCopy["PrimePart"]
						PlantCopy:MoveTo(Target.Position)
						PlantCopy.Parent = game.Workspace
						curT = Target
					else
						
					end
				end
			end
		end
	end
	
end);

2 answers

:MoveTo() will only attempt to move your model to a given position if it doesn't collide with other objects. If that is the case the model will move up in the Y direction until it finds a free space. Seeing as you want to move it to another model that will go wrong almost immediately.

Additionally you are using Mouse.Target which is the part your cursor is aiming at, the position of that is the centerpoint of said part, not the location your cursor is pointing to. I am guessing that's not what you want but if it is then can ignore the next part.

You probably want to use Mouse.Hit.p which is the location your cursor is pointing to in the worldspace.

I think I understand. I just made up a little example to make sure we're on the same page, I'm not entirely concerned about the position as long as it's centred to the part I'm hovering over.

Example

Right now when I hover over the part I can see Plant1 being moved to workspace but it's not going to the position of the grid part that is being hovered over. It's just spawning in the place in-which I moved it into ReplicatedStorage.

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