Is there a way to disable equipping/unequipping tools when performing an action?

i know this post exists, but it doesn’t work (atleast for me)

i’m looking for a method that can disable equipping and/or unequipping tools during an action

reloading for example, if you switch weapons when you reload the game kind of… breaks
i really don’t wanna code in additional checks and stuff, so i figured i’d just disable equipping + unequipping

but how can i disable those and make them exploit proof (to prevent exploiters from… kicking themselves because of the anticheat)

For an FPS game, most games tend to cancel the reload of a gun if they’re being unequipped/switched to another weapon. So why not do that?

I dont know if this is what you are looking for but I use

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

I would use that right before you reload and then

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)

but i want to disable equipping entirely

because i’m sadistic and want people to suffer for doing something in the wrong time

nooo this doesn’t work at all charrrrrrrrrrr

could i see your scripts? and couldnt you just have a value in the script called reloading and if reloading == true then dont let the player switch weapons?

that is literally what i’m asking on how to do (i don’t know how)

although my beautiful code doesn’t have much relevancy:
(cropped because there’s not that much stuff to see)

connection = UIS.InputBegan:Connect(function(input)
			if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
			if input.KeyCode ~= Enum.KeyCode.R then return end
			if Shooting.Value then return end
			if Reloading.Value then return end
			if Bullets.Value == MAX_BULLETS then return end
			if Equipping.Value then return end
			
			if Bullets.Value > 0 then
				starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
				local ReloadAnim = animator:LoadAnimation(Reload)
				
				ReloadAnim:Play()
				ReloadEvent:FireServer()
				task.wait(ReloadAnim.Length)
				starterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
			else
				local EmptyReloadAnim = animator:LoadAnimation(EmptyReload)
				EmptyReloadAnim:Play()
				ReloadEvent:FireServer()
			end
		end)

Unfortunately I don’t think you can with the default backpack gui and you would have to code your own if you still want to use Tools without modifying and/or breaking them.

Otherwise, @GalladeR475 is right. Players are more punished switching guns than reloading most of the time anyways (if implemented properly).

What I would do is create a boolvalue in the player named “reloading”, and when the player presses R, change the reloading value to true, wait however long reloadtime is, then turn reload to false. Then with whatever script you have for equipping weapons I would try to disable backpack which would make the player not be able to access their weapons, or you would have to create a custom toolbar.

Tool.Enabled

Humanoid.UnequipTools(), if you want to unequip tools (multiple tools might be equipped).

Just for loop through the player.Backpack’s children and then set the Tool.Enabled to false.

local function toggleTools(boolean)
   for _, tool in pairs(player.Backpack:GetChildren()) do
      if not tool:IsA("Tool") then continue end
      tool.Enabled = boolean
   end
end
1 Like

i think you might’ve just cooked, i’ll try this and let you know

1 Like

i have terrible news (it doesn’t work)

though i don’t know if i’m doing it incorrectly (i don’t think so):

ReloadEvent.OnServerEvent:Connect(function(player)
	local tool = player.Character:FindFirstChildOfClass("Tool")	
	local reloading = tool.Reloading
	local shooting = tool.Shooting
	
	local function toggleTools(boolean)
		for _, tool in pairs(player.Backpack:GetChildren()) do
			if not tool:IsA("Tool") then continue end
			tool.Enabled = boolean
		end
	end

	if tool.Bullets.Value > gunInfo[tool.Name]["MAX_BULLETS"] then player:Kick("Gluttony is a sin.") return end
	if tool.Equipping.Value then player:Kick("Someone's in a hurry.") return end
	if shooting.Value then player:Kick("Keep trying.") return end
	if reloading.Value then player:Kick("Very funny.") return end
	toggleTools(false)
	tool.Unequipped:Connect(function()
		reloading.Value = false
	end)

	-- // NORMAL RELOAD
	if tool.Bullets.Value > 0 then
		reloading.Value = true

		local NORMAL_MAGAZINE_PULL_TIME = gunInfo[tool.Name]["NORMAL_MAGAZINE_PULL_TIME"]
		local NORMAL_MAGAZINE_INSERT_TIME = gunInfo[tool.Name]["NORMAL_MAGAZINE_INSERT_TIME"]
		local NORMAL_FINISH_RELOAD_TIME = gunInfo[tool.Name]["NORMAL_FINISH_RELOAD_TIME"]

		local PullMagazineSound = tool.Magazine.PullMagSound
		local InsertMagazineSound = tool.Magazine.InsertMagSound


		while reloading.Value do
			if not reloading.Value then break end
			
			task.wait(NORMAL_MAGAZINE_PULL_TIME)
			if not reloading.Value then break end
			PullMagazineSound:Play()
			tool.Bullets.Value = 0

			task.wait(NORMAL_MAGAZINE_INSERT_TIME)
			if not reloading.Value then break end
			InsertMagazineSound:Play()
			tool.Bullets.Value = gunInfo[tool.Name]["MAX_BULLETS"]

			task.wait(NORMAL_FINISH_RELOAD_TIME)
			reloading.Value = false
			toggleTools(true)
		end
		-------------------------------------------------------------------------------

		-- // EMPTY RELOAD
	elseif tool.Bullets.Value == 0 then
		reloading.Value = true

		local EMPTY_MAGAZINE_PULL_TIME = gunInfo[tool.Name]["EMPTY_MAGAZINE_PULL_TIME"]
		local EMPTY_MAGAZINE_INSERT_TIME = gunInfo[tool.Name]["EMPTY_MAGAZINE_INSERT_TIME"]
		local EMPTY_BOLT_PULL_TIME = gunInfo[tool.Name]["EMPTY_BOLT_PULL_TIME"]
		local EMPTY_FINISH_RELOAD_TIME = gunInfo[tool.Name]["EMPTY_FINISH_RELOAD_TIME"]

		local PullMagazineSound = tool.Magazine.PullMagSound
		local InsertMagazineSound = tool.Magazine.InsertMagSound
		local BoltPullSound = tool.Bolt.PullBoltSound


		while reloading.Value do
			if not reloading.Value then break end	
			
			task.wait(EMPTY_MAGAZINE_PULL_TIME)
			if not reloading.Value then break end
			PullMagazineSound:Play()
			tool.Bullets.Value = 0

			task.wait(EMPTY_MAGAZINE_INSERT_TIME)
			if not reloading.Value then break end
			InsertMagazineSound:Play()
			tool.Bullets.Value = gunInfo[tool.Name]["MAX_BULLETS"]

			task.wait(EMPTY_BOLT_PULL_TIME)
			if not reloading.Value then break end
			BoltPullSound:Play()

			task.wait(EMPTY_FINISH_RELOAD_TIME)
			reloading.Value = false
			toggleTools(true)
		end
	end
end)

At this point I suggest to do 2 things.

  1. Make a module script which handles the Equipped, Unequipped, Activated and Deactivated of the tool. This tool cancels sending an Equipped event if you are unable to equip a tool.
  2. When you tell the module script to stop equipping tools on the Equipped event of any tool it just defaults back to Humanoind:UnequipTools() and then forces the tool which you had equipped before back on with Humanoid:EquipTool().
local ToolHandler = {}

local canEquip = true
local previousTool = nil

function ToolHandler.Equipped(tool, equippedFunc)
   return tool.Equipped:Connect(function(...)
      if not canEquip and previousTool ~= tool then 
         -- humanoid unequip + humanoid equip previousTool
         return
      end
      equippedFunc(...)
   end)
end

function ToolHandler.Unequipped(tool, unequippedFunc)
    return tool.Unequipped(unequippedFunc)
end

function ToolHandler.Activated(tool, activatedFunc)
   return tool.Activated:Connect(function(...)
      if not canEquip and previousTool ~= tool then 
         -- humanoid unequip + humanoid equip previousTool
         return
      end
      activatedFunc(...)
   end)
end

function ToolHandler.Deactivated(tool, deactivatedFunc)
   return tool.Unequipped:Connect(tool)
end

function ToolHandler.DisableEquip(tool)
    canEquip = false
    previousTool = tool
end

function ToolHandler.EnableEquip()
    canEquip = true
    previousTool = nil
end

return ToolHandler

1 Like

unnecessarily complicated, why couldn’t this be a simple one liner aiojgfouiaduhjniupfhsd

I literally just made you a module script which is going to work properly :sob:.
Now instead of tool.Equipped:Connect(func) or tool.Activated:Connect(func) use:
ToolHandler.Equipped(tool, func)

Then just use:
ToolHandler.DisableEquip(tool) (this would be the tool you want to keep equipped).
Wait a bit and then use ToolHandler.EnableEquip()

Also I just realise this will only work if you equip another tool, I recommend also adding this:

-- on top
local unequipCon

-- inside DisableEquip
if unequipCon then unequipCon:Disconnect() unequipCon = nil end
unequipCon = tool.Unequipped:Connect(function() 
   -- equip the tool back with the humanoid function 
end)

-- inside EnableEquip
if unequipCon then unequipCon:Disconnect() unequipCon = nil end
1 Like

This is because you wanted to do it this way.
Or else it wouldn’t have been so complicated.

1 Like

alr noted,

will try this tomorrow because i do not feel like going through all of this rn

This seems solid, give it a try and let us know how it works.

1 Like

but ummmmm

i don’t want unequipping weapons!!!