Tool that cant be unequipped

How do I make a tool being impossible to unequip at a certain moment?
Simply re-equipping it through Humanoid:EquipTool() or Tool.Parent = Character, as it sometimes
(for some reason) causes the equip-unequip cycle, pressuring the CPU.

If that’s impossible with Roblox’s basic modules, how to edit those (and which are) responsible for tools?

1 Like

After equipping, a timer can be started which only then allows unequipping.

local CanUnequipp = false -- Whether we can Unequipp it
local WaitForUnequipp = false -- When we alr start a task.spawn

script.Parent.Equipped:Connect(function()
	
	if WaitForUnequipp == false then
		
		WaitForUnequipp = true
		
		task.spawn(function()
			
			task.wait(5)
			
			WaitForUnequipp = false
			CanUnequipp = true
			
		end)
		
	end
	
end)

script.Parent.Unequipped:Connect(function()

	if CanUnequipp == false then
		script.Parent.Parent.Parent.Character:WaitForChild("Humanoid"):EquipTool(script.Parent) -- <-- Get here your Humanoid and then do the EquipTool functions.
	end
	
	if CanUnequipp then
		CanUnequipp = false
	end

end)

Already told that blunt Humanoid:EquipTool() can cause equip-unequip cycles.

there is no other way lol

1 Like

Custom gear equip/unequip system/GUI ?

Is there a way to edit Roblox’s core scripts to add functionality? If yes, which core script is responsible for equipping/unequipping?

1 Like

Then deactivate the StarterGUI. If it is deactivated, you can no longer equip or unquip an Item. We activate it again after a while or during a remote event. After that, the player can unquip it again without the loop occurring.

local StarterGui = game:GetService("StarterGui")

local WaitForUnequipp = false -- When we alr start a task.spawn

script.Parent.Equipped:Connect(function()
	
	if WaitForUnequipp == false then
		
		WaitForUnequipp = true
		
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
		
		task.wait(5)
		
		StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
		
		WaitForUnequipp = false
		
	end
	
end)

I don’t know if there is a way to directly edit roblox’s core scripts but there is a method to remove/disable default inventory system. And if combine this with simple logic like to detect when an instance is added into the backpack (what else can be in there), create GUI and add your custom Equip/Unequip functions.
Fast example:

local StarterGui = game:GetService("StarterGui")

StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) -- make roblox's default inventory system invisible/disabled

local backpack = game.Players.LocalPlayer.Backpack
local hum = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid")


local function EquipGear(toolName)
	hum:EquipTool(backpack:FindFirstChild(toolName))
end

local function UnequipTools()
	hum:UnequipTools()
end

local function GearAdded()
	-- Some GUI logic
	-- For instance to add button on a Frame with UIListLayout and detect when it gets clicked
	-- If done and the button is created:
	btn.MouseButton1Click:Connect(function()
		EquipGear(btn.Name)
	end)
end

local function GearRemoved()
	btn:Destroy()
end

backpack.ChildAdded:Connect(GearAdded)
backpack.ChildRemoved:Connect(GearRemoved)

You can’t modify core scripts on Roblox. You may get away with some things in studio but nothing will ever replicate.

You’ll need to make your own functionality if none of the already stated solutions suit your needs.

1 Like

I see. Thanks for explaining, and not thanks to Roblox for not creating the simplest function ever imaginable.

1 Like