|
| 13 May 2014 02:57 PM |
How do I make it so when a player clicks "1" then they equip a tool, and when they click 1 again, then the player unequipped the tool?
I removed the old tool bar, and now i'm making a custom one, so how would I do this? |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 03:00 PM |
local player = game.Players.LocalPlayer local mouse = game.Players.LocalPlayer:GetMouse() tool = script.Parent
mouse.KeyDown:connect(function(key) if key:byte() == 49 then tool.Parent = player.Character end end)
mouse.KeyUp:connect(function(key) if key:byte() == 49 then if player.Character:FindFirstChild(tool.Name) then player.Character.tool.Parent = player.Backpack end end end) |
|
|
| Report Abuse |
|
|
Ultraw
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 6575 |
|
|
| 13 May 2014 03:01 PM |
player = game.Players.LocalPlayer mouse = player:GetMouse()
function onKeyDown( key ) if key=="1" then --i think numbers work fine player.Character.Humanoid:EquipTool(player.Backpack.WEAPON) end mouse.KeyDown:connect(onKeyDown) |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 03:02 PM |
| eh I guess my script would unequip when you let go of 1 xD sorry |
|
|
| Report Abuse |
|
|
Ultraw
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 6575 |
|
|
| 13 May 2014 03:04 PM |
equipped = false
player = game.Players.LocalPlayer mouse = player:GetMouse()
function onKeyDown( key ) if key=="1" then if equipped = false then equipped = true player.Character.Humanoid:EquipTool(player.Backpack.WEAPON) else player.Character.Humanoid:UnequipTools() end mouse.KeyDown:connect(onKeyDown) |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 03:05 PM |
@ultraw
I think you forgot an end, because the last line is underlined red.
and would this go inside the tool, or the handle? |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 03:07 PM |
| It would go inside a localscript inside the tool. |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 03:08 PM |
"I think numbers would work fine." No, key:byte() is what you need for things like that. Plus, numbers arent a string. |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 03:09 PM |
This is underlined.
10) if equipped = false then |
|
|
| Report Abuse |
|
|
| |
|
Ultraw
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 6575 |
|
| |
|
|
| 13 May 2014 03:14 PM |
| Then wouldn't there be 2 ends at the bottom? |
|
|
| Report Abuse |
|
|
SLY3
|
  |
| Joined: 10 Jul 2008 |
| Total Posts: 1700 |
|
|
| 13 May 2014 03:14 PM |
| change it to if equipted == false then |
|
|
| Report Abuse |
|
|
| |
|
|
| 13 May 2014 03:18 PM |
equipped = false weapon = "NAME OF WEAPON" --I added this, change it to the name of the weapon
player = game.Players.LocalPlayer mouse = player:GetMouse()
function onKeyDown( key ) if key=="1" then if equipped == false then equipped = true player.Character.Humanoid:EquipTool(player.Backpack[weapon]) else player.Character.Humanoid:UnequipTools() end end end mouse.KeyDown:connect(onKeyDown) |
|
|
| Report Abuse |
|
|
|
| 13 May 2014 03:19 PM |
equipped = false weapon = "NAME OF WEAPON" --I added this, change it to the name of the weapon
player = game.Players.LocalPlayer mouse = player:GetMouse()
function onKeyDown( key ) if key:byte() == 49 then if equipped == false then equipped = true player.Character.Humanoid:EquipTool(player.Backpack[weapon]) else player.Character.Humanoid:UnequipTools() end end end mouse.KeyDown:connect(onKeyDown)
Use this one instead, forgot to change the key checking into key:byte() == 49 |
|
|
| Report Abuse |
|
|