How do I make a when I press a keybind I equip a tool

How do I make a when I press a keybind I equip a tool
e.g I want to put a tool in my hand instead of pressing it I press R

Use UserInputService | Roblox Creator Documentation or ContextActionService | Roblox Creator Documentation to bind the key and Humanoid | Roblox Creator Documentation to equip the tool.

local ContextActionService = game:GetService('ContextActionService')
local Players = game:GetService('Players')

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local tool = -- tool

local function equipAction(name, state, obj)
if state == Enum.UserInputState.Begin then
if character:FindFirstChild(tool.Name) then
character.Humanoid:UnequipTools()
else
character.Humanoid:EquipTool(tool)
end
end
end

ContextActionService:BindAction(
'equipKeybind', 
equipAction, 
false, 
Enum.KeyCode.R
)
4 Likes

Using IsKeyDown:

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function()
	local E = UIS:IsKeyDown(Enum.KeyCode.E)
	local A = UIS:IsKeyDown(Enum.KeyCode.A)
	if E and A then
		-- Code --
	end
end)

You would just do something like: Humanoid:ToolEquip() or something like that. Im on mobile so I cant very well script.

ok thank you man ima test it :smile: :grinning: :smiley: :grinning_face_with_smiling_eyes:

1 Like

but where should it go
:thinking: :thinking:

1 Like

umm hello? :roll_eyes: :grimacing: :expressionless: :neutral_face:

It should go inside the tool as a LocalScript, also replace -- tool with script.Parent.

o well i just put it in starterplayerscript and it works