generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How do I.....

Previous Thread :: Next Thread 
ZeroHour66 is not online. ZeroHour66
Joined: 14 Sep 2013
Total Posts: 1511
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
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
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 is not online. 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
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
13 May 2014 03:02 PM
eh I guess my script would unequip when you let go of 1 xD sorry
Report Abuse
Ultraw is not online. 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
ZeroHour66 is not online. ZeroHour66
Joined: 14 Sep 2013
Total Posts: 1511
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
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
13 May 2014 03:07 PM
It would go inside a localscript inside the tool.
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
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
ZeroHour66 is not online. ZeroHour66
Joined: 14 Sep 2013
Total Posts: 1511
13 May 2014 03:09 PM
This is underlined.

10) if equipped = false then
Report Abuse
DeSpizer27 is not online. DeSpizer27
Joined: 13 Jul 2012
Total Posts: 2679
13 May 2014 03:09 PM
if equipped == false then
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
13 May 2014 03:13 PM
Sorry, I make mistakes :(
Report Abuse
ZeroHour66 is not online. ZeroHour66
Joined: 14 Sep 2013
Total Posts: 1511
13 May 2014 03:14 PM
Then wouldn't there be 2 ends at the bottom?
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
13 May 2014 03:14 PM
change it to if equipted == false then
Report Abuse
ZeroHour66 is not online. ZeroHour66
Joined: 14 Sep 2013
Total Posts: 1511
13 May 2014 03:17 PM
i did.
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
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
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image