why does it print multiple times instead one that i'm trying to do, and how can i fix this?
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local part = game.Workspace.Part while true do mouse.TargetFilter = part part.Position = mouse.Hit.p mouse.Button1Down:connect(function() print(true) return end) wait() end
That connect
method does not yield so there is no reason for the script to not make that connection every single loop. This is VERY bad it makes new functions each time which eats memory.
Also return
cannot break any environment except the current function, so that one does nothing. You should separate these things.
Assuming you want the mouse to constantly be on the part until click:
--be more careful with initalization local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local part = workspace:WaitForChild("Part") mouse.TargetFilter = part local clicked = false mouse.Button1Down:Connect(function() clicked=true end) repeat part.Position = mouse.Hit.p wait() until clicked==true