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 part follow mouse then place on click?

so i have tried doing this in a localscript because for now i am making it local until it actually spawns a part then i will make it fire an event later and make the server create it instead of the client

--localscript
 game.Players.PlayerAdded:Connect(function(plr)
	local Mouse = plr:GetMouse()
	local cloth = game.ReplicatedStorage.Cloth
	cloth.Position = Mouse.Target.Position

	if Mouse.Button1Down then
		cloth.Position = Mouse.Target.Postion
		cloth.Anchored = true
	end
end)

1 answer

✓ Accepted answer

I would do it like this, insert a Local Script into Starter Gui and then the following code into the script (Yours but slightly modified)

play = game.Players.LocalPlayer
char = play.Character
mouse = play:GetMouse() --Gets the Players Mouse
cloth = game.ReplicatedStorage.Cloth:Clone() --Clones the part

mouse.Button1Down:Connect(function() --Fires if Button1 Is Clicked
	cloth.Position = mouse.Hit.p --Part position = mouse.Position
	cloth.Parent = workspace
	cloth.Anchored = true
end)

Hopefully this helped.

EDIT Improved Script

play = game.Players.LocalPlayer
char = play.Character
mouse = play:GetMouse() --Gets the Players Mouse
cloth = game.ReplicatedStorage.Cloth:Clone() --Clones the part
clothplacing = game.ReplicatedStorage.Cloth:Clone()

mouse.Move:Connect(function()
	clothplacing.Position = mouse.Hit.p
	clothplacing.Anchored = true
	clothplacing.Parent = char --Parented here so that it's not detected by the mouse Position and therfore wont infintely climb up the Y axis
	wait()
end)

mouse.Button1Down:Connect(function() --Fires if Button1 Is Clicked
    cloth.Position = clothplacing.Position
    cloth.Parent = workspace
    cloth.Anchored = true
end)

Best I can do, sorry.

6 comments

0

use local variables

0

Why does that matter out of curiosity? And I just realized that I read his question completely wrong, will change the script.

0

alright this worked tysm ill be converting it to FE later so i might need help with that idk

0

I tried including the part constantly moving the with mouse until placed but it kept climbing up the Y axis, if its important though I could probably find a solution.

0

if you can yes that is what i was going for

0

Did my best.

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