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

How to convert this from Hopperbin to Workspace?

Asked by 9 years ago

Basically, what I'm asking is, how do I convert this to the Workspace? And instead of clicking on the part, you press E, and the part floats until you press E again. Basically, I'm trying to mimic the Source Engine's pick up function with this script.

local PartNames = {"Cube", "Crate", "Box"}
local DistanceLimit = 10 --You must be within so many studs to pick up a part.


--Variables
local MovingObject = false
local Plyr = game.Players.LocalPlayer
local Tool = script.Parent


--General Functions
Move = (function (Mouse, Obj)
    local BodyPosition, CharTorso = Instance.new("BodyPosition",Obj), Plyr.Character.Torso; 
    BodyPosition.maxForce = Vector3.new(Obj.Size.X*5000,Obj.Size.Y*5000,Obj.Size.Z*5000)
    MovingObject = true
    while (MovingObject and (CharTorso.Position-Obj.Position).magnitude < DistanceLimit) do
        BodyPosition.position = (CFrame.new(CharTorso.Position, Mouse.Hit.p) * CFrame.new(0,0,-DistanceLimit + 3)).p
        wait(0.1)
    end
    MovingObject = false
    BodyPosition:Destroy()
end)

--Event Handlers
Tool.Selected:connect(function (Mouse)
    Mouse.Button1Down:connect(function ()
        if MovingObject then 
            MovingObject = false 
            return 
        end
        local MouseTarget = Mouse.Target;
        if not MouseTarget or not PartNames[MouseTarget.Name] or MouseTarget.Anchored 
            or (Plyr.Character.Torso.Position-MouseTarget.Position).magnitude > DistanceLimit then 
            return 
        end
        Move(Mouse, MouseTarget);
    end)
end)

Tool.Deselected:connect(function ()
    MovingObject = false
end)

--Convert table from {"names"} to {names = true} for convenience
for i=1, #PartNames do
    PartNames[PartNames[i]] = true
    PartNames[i] = nil
end

1 answer

Log in to vote
1
Answered by 9 years ago
mouse.KeyDown:connect(function(key))
    if key == "e" then
        --do stuff
    end
end)
0
I think this probably went completely over your head. That wouldn't work. :P TheRings0fSaturn 28 — 9y
0
I don't see why not. :P Protoduction 216 — 9y
Ad

Answer this question