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

How to make a model be dragged with your mouse and onClick be placed?

I anm trying to make a script where when you click and drag a model with your mouse it moves and when you click it spawns the place you clicked. Please fix it and please dont make a local script in starterplayer just make it in the model please. There is a script in the block covering the whole object that you click and move with a click detector. please help I stink at scripting!

local mouse = mouse:GetMouse()
local p = script.Parent.ClickDetector

script.Parent.ClickDetector.MouseClick:Connect(function(onClick)
	script.Parent.Parent:MoveTo(mouse.Hit.p)
	if p == true then
		model:Clone().Parent = game.Workspace.Tycoon
	end
end)

2 comments

0

Keeping the shape of the model while dragging it would be really tough. Consider turning the model into either a union or a mesh. If you're not willing to do that, I really don't know how to answer your question. Good luck.

1 answer

✓ Accepted answer

What Lost said is important but a couple side notes:

You should be using UserInputService to figure out when they clicked and not a click detector inside of the objects. In order to make the model go to your mouse's location, you either have to have to put the model inside the player's character, or create your own raycasting, because the way mouse.Hit naturally works is it will ignore targets in the player and nothing else, so if you were to have the mouse over the model while placing it when you clicked it would register your mouse being on top of the model you're dragging and ont the floor below it.

Basically when moving the model use SetPrimaryPartCFrame, but make sure you have it inside the player's model and use UserInputService to make it work properly

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