Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to convert this from Hopperbin to Workspace?

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

✓ Accepted answer
mouse.KeyDown:connect(function(key))
	if key == "e" then
		--do stuff
	end
end)

2 comments

0

I think this probably went completely over your head. That wouldn't work. :P

0

I don't see why not. :P

This discussion is preserved as it was. New answers, comments, and votes are closed.