✓ Accepted answer
In theory, you do not need to put click detectors and the same script in EVERY part or model. You can simply use the HopperBin that ROBLOX has to simulate both not holding a tool, and reaching these goals of moving the object. In fact, people have already done this and created free models, such as the great Malvaviscos. His answer was simple.
Note I do not take credit for this in any way, this scripting is done by Malvaviscos and used in his Force Grip model.
holdRadius = 15
maxSelectRadius = 30
local position = Instance.new("BodyPosition")
position.Name = "Pos"
position.maxForce = Vector3.new(100000,100000,100000)
local object = nil
function onButton1Down(mouse)
if mouse.Target ~= nil then
if (mouse.Target.Position - game.Players.LocalPlayer.Character.Head.Position).magnitude <= maxSelectRadius and not mouse.Target.Anchored then
object = mouse.Target
position.Parent = object
position.position = game.Players.LocalPlayer.Character.Head.Position + (mouse.Hit.p - game.Players.LocalPlayer.Character.Head.Position).unit * holdRadius
down = true
end
end
end
function onButton1Up(mouse)
object = nil
position.Parent = nil
down = false
end
function onMove(mouse)
if down then
position.position = game.Players.LocalPlayer.Character.Head.Position + (mouse.Hit.p - game.Players.LocalPlayer.Character.Head.Position).unit * holdRadius
end
end
function onSelected(mouse)
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
mouse.Button1Up:connect(function() onButton1Up(mouse) end)
mouse.Move:connect(function() onMove(mouse) end)
end
script.Parent.Selected:connect(onSelected)
script.Parent.Deselected:connect(onButton1Up)
4 comments
I'm reposting this because no one is answering.
help me already
can you elaborate on what happens and what's supposed to happen? I don't understand the goal of these pictures.
Did you weld the rest of the box to the part that moves?