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

How would I go about equipping a Hopperbin using a key-press?

Hi! - I am working on a game that has it's own GUI - meaning that the CoreGUI is no longer needed. I have disabled the CoreGUI - but I would like to equip the tool using the same keys that ROBLOX uses (1,2,3,4,5,6,7,8,9,0). I did some looking around, and found a couple different methods. I decided to go with this one -

local num = nil
local currentToolNum = nil
local plr = game.Players.LocalPlayer

function ToolDecision(number, player)
if number == currentToolNum then
player.Character.Humanoid:UnequipTools()
currentToolNum = nil
else
player.Character.Humanoid:UnequipTools()
local tools = player.Backpack:GetChildren()
table.sort(tools, function(a,b) return a.ToolNumber.Value < b.ToolNumber.Value end);
wait()
if #tools >= number then
currentToolNum = tools[number].ToolNumber.Value
player.Character.Humanoid:EquipTool(tools[number])
end
end
end

mouse = plr:GetMouse()
mouse.KeyDown:connect(function(key)
if key == string.char(48) then
num = 10
ToolDecision(num, plr)
elseif key == string.char(49) then
num = 1
ToolDecision(num, plr)
elseif key == string.char(50) then
num = 2
ToolDecision(num, plr)
elseif key == string.char(51) then
num = 3
ToolDecision(num, plr)
elseif key == string.char(52) then
num = 4
ToolDecision(num, plr)
elseif key == string.char(53) then
num = 5
ToolDecision(num, plr)
elseif key == string.char(54) then
num = 6
ToolDecision(num, plr)
elseif key == string.char(55) then
num = 7
ToolDecision(num, plr)
elseif key == string.char(56) then
num = 8	
ToolDecision(num, plr)
elseif key == string.char(57) then	
num = 9
ToolDecision(num, plr)
end
end)

(see [(http://http://www.roblox.com/Forum/ShowPost.aspx?PostID=131828807])

The post specifies that the tool (or in this case, the Hopperbin) should have a value inside of it named ToolNumber. I have created that, and set the value to 1.

This should make it so when the '1' key is pressed, the player should equip the Hopperbin. Unfortunately, that doesn't seem to work. I suspect it is because it is using 'Tool' instead of Hopperbin - but I thought I would ask here first.

Thanks in advance

  • Dragon

EDIT: This does not seem to work with a tool either.

It should be said that this must be used with a hopperbin, as the game requires the hopperbin in order to work.

It is displaying the error ToolNumber is not a valid member of LocalScript. However, when put into a normal script, the error persists.

Line 12 is also seems to be the center of the problem, but I can't figure out what is causing it.

1 answer

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