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

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

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

http://wiki.roblox.com/index.php?title=Taking_keyboard_input#Full_list

0
I am sorry, but this is not the answer I was looking for - the script recognizes that the key has been pressed, but errors with ToolNumber is not a valid memeber of LocalScript. HypocriticalDragon 40 — 10y
0
And it should also be stated that the problem persists when using a normal script. HypocriticalDragon 40 — 10y
Ad

Answer this question