Unequip Tools from button

I am trying to have a keyboard button unequip the weapon you’re holding, I just have no idea how to make this besides using UserInputService.

4 Likes

Why don’t you want to use UserInputService? If you really don’t want to use it, you can use ContextActionService to make keybinds. For unequipping the tools you can just use Humanoid:UnequipTools, which, in addition to being the solution, also provides a very good example of unequipping tools from a button press.

I worded that wrong, I meant I have know idea how to make this besides the fact that I should use UserInputService

Oh ok, that makes much more sense. Now that I think about it, ContextActionService is better than UserInputService, but I’ll give an example of both.

UserInputService:

local uis = game:GetService("UserInputService")
local lplr = game:GetService("Players").LocalPlayer

uis.InputBegan:Connect(function(i,g)
	if g == true then return end

	if i.KeyCode == Enum.KeyCode.F then
		local c= lplr.Character
		if c == nil then return end
		local h = c:FindFirstChildWhichIsA("Humanoid")
		if h == nil then return end
		h:UnequipTools()
	end
end)

ContextActionService:

local cas = game:GetService("ContextActionService")
local lplr = game:GetService("Players").LocalPlayer

local makeMobileButton = false

cas:BindAction("toolUnequipper",function()
	local c= lplr.Character
	if c == nil then return end
	local h = c:FindFirstChildWhichIsA("Humanoid")
	if h == nil then return end
	h:UnequipTools()
end,makeMobileButton,Enum.KeyCode.F)

I recommend to use the ContextActionService one, although you can use UserInputService. The keybind is currently f, but you can change it in either one by changing the enum.

Sorry about the really late response

2 Likes

Its fine, where should I put the script?

put the script in starterplayer>starterplayerscripts. Make sure it’s a localscript.

Alright, thanks for the help! (all the 30 cc)