So here is a script that enables the player to click and drag a unioned part. What is necessary to add to this to make sure players are not able to drag the part from a certain distance?
plr = game.Players.LocalPlayer mouse = plr:GetMouse() target = {} script.Parent = game.StarterPlayer.StarterPlayerScripts function click() if mouse.Target then if mouse.Target:IsA("UnionOperation") and mouse.Target.Locked == false then target.part = mouse.Target target.anchored = target.part.Anchored target.part.Anchored = true dim = true mouse.Move:connect(function() if dim then target.part.CFrame = CFrame.new( mouse.Hit.X,target.part.CFrame.Y,mouse.Hit.Z) elseif not dim then end end ) mouse.Button1Up:connect(function() dim = false target.part.Anchored = target.anchored end) end end end mouse.Button1Down:connect(click)
Hi Bunny!
The correct operation for finding the distance between two parts is this:
local distance = (partA.Position - partB.Position).magnitude
Measured in studs. This method also works for Vector3's for future reference.
The most encouraged way, at least from me, is that you find the distance between your character's torso and the target block. The easiest way I see is to place it within your second conditional as I do here:
if mouse.Target:IsA("UnionOperation") and mouse.Target.Locked == false and ((plr.Character:WaitForChild('Torso').Postion - mouse.Target.Position).magnitude < 10) then
Keep on coding! ~ HollowMarofan
In the properties of the Click Detector, you should see " Max Activation Distance. You can change it.