Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a part follow mouse then place on click?

Asked by
Donut792 216 Moderation Voter
5 years ago

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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

0
use local variables User#23365 30 — 5y
0
Why does that matter out of curiosity? And I just realized that I read his question completely wrong, will change the script. nicktooner 119 — 5y
0
alright this worked tysm ill be converting it to FE later so i might need help with that idk Donut792 216 — 5y
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. nicktooner 119 — 5y
View all comments (2 more)
0
if you can yes that is what i was going for Donut792 216 — 5y
0
Did my best. nicktooner 119 — 5y
Ad

Answer this question