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 » Scripters
Home Search
 

Re: How do I script a hotkey to equip a sword?

Previous Thread :: Next Thread 
Robometabot is not online. Robometabot
Joined: 25 Jun 2009
Total Posts: 171
09 Oct 2017 01:55 PM
I want to be able to press Q to equip a sword in my backpack, but I don't want the player to be able to press 1-9 to equip it. How do I do this?
Report Abuse
LotsOfViolence is not online. LotsOfViolence
Joined: 29 Jun 2011
Total Posts: 8375
09 Oct 2017 02:00 PM
Custom backpack.
Report Abuse
Robometabot is not online. Robometabot
Joined: 25 Jun 2009
Total Posts: 171
09 Oct 2017 02:01 PM
Custom backpack? This would be a local player script correct?
Report Abuse
gohan31865 is not online. gohan31865
Joined: 30 Jan 2011
Total Posts: 895
09 Oct 2017 02:26 PM
yes


#code error("you're*")
Report Abuse
Degreds is not online. Degreds
Joined: 30 Nov 2013
Total Posts: 367
09 Oct 2017 02:33 PM
You do need a custom backpack, but you're going to need to do the GUI yourself. Try putting the tool in a folder in StarterPack. This will make the tool un-equippable with 1-9. Also, this may get long.

Here's a simple script you can put inside the tool to toggle the tool with the Q key:

player = script.Parent.Parent.Parent -- haven't tested this, you might have to fiddle with it
repeat wait() until player.Character
char = player.Character

tool = script.Parent
equipped = false
customBackpack = tool.Parent -- tool.Parent should be the folder I mentioned previously.

-- The tool should also be a regular model instead of a tool. This is to prevent players pressing 1-9 to equip it.
-- Next, you have to make it stick to the character's hand. You can try looking up a tutorial online for it 'cuz I wanted to keep this simple.

-- Here's the function to toggle the tool. Take note that this will NOT be welded to the character's hand the way I have it now.

game:GetService("UserInputService").InputBegan:connect(function(key) -- UserInputService handles all keyboard inputs.
if key.KeyCode == Enum.KeyCode.Q then -- The key variable is the key pressed. This line tests if they keycode of it is Q.
if equipped == false then
tool.Parent = char
else
tool.Parent = customBackpack
end
end
end)
Report Abuse
LaeMVP is online. LaeMVP
Joined: 24 Jun 2013
Total Posts: 4416
09 Oct 2017 02:38 PM
local plr = game.Players.LocalPlayer
local yourTool = ???
game:GetService("UserInputService").InputBegan:Connect(function(key,gpe)
if key.KeyCode == Enum.KeyCode.Q and not gpe then
if not plr.Character then return end
plr.Character.Humanoid:EquipTool(yourTool)
end
end)
Report Abuse
Robometabot is not online. Robometabot
Joined: 25 Jun 2009
Total Posts: 171
09 Oct 2017 08:33 PM
Thank you so much Degreds. I'll get back to you tomorrow when I can try this and let you know how it goes (:
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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