How to make the player un-equip their tool before equipping another

So, I want to make it so that the player has to unequip the item they’re holding before they equip another. Sorta like RE:COM, As you can see here:

Any tips or advice, Or anywhere to start? RE:COM isn’t easy to edit, Or look into.

1 Like

You can create an object value, or use a variable to indicate that the player is currently using a weapon. If the player is, then you will implement your unequip logic, by either destroying the model and / or tool or :Unequip()

Pretty sick idea, But how would i then make the script recognise what tool the player’s trying to equip?

I don’t exactly understand what you mean but this structure should give you a background:

  • Create the logic where a gun is equipped.
  • In our equip logic, we will create an objectValue, or a variable, and set the value of it to the gun.
  • Now we know what tool is currently equipped, so we will go back to our equip logic then;
  • Create an if statement, that will check if the objectValue exist, and if there is a weapon equipped.

You can get the gun by objectValue.Value (This is now the gun Instance), I didn’t really understand so do you mind explaining?

I meant to say that,

If i did this code, Would it be able to detect what other tool im trying to equip?

Because let’s say i do this, And i make it unequip the current tool that player has equipped.

How would it then get the next tool that im trying to equip?

Seems like you want it to automatically:

unequip, pause, then equip.

That is how I would explain what I saw in the video. I’m not sure how you would do this without a custom backpack GUI.

I would describe your post title to mean:

don’t let player equip an item unless there is no item equipped

Yeah, this is sorta what i want.

The fella that made RE:COM was able to do it without a custom GUI, So, Still tryna figure this out

1 Like

My idea here is if the item being equipped using the findfirstchildofclass on the character. If it isn’t, then we equip the item they were trying to switch to. If it is true, then the original tool should be equipped using the tool:Equip() function. We can use the .Unequipped and .Equipped to fire the animation and you could make the backpack feature disabled before re-enabling when it is fully unequipped.

So that is just an animation running between switching I think. The basic backpack seems to house the weapons as seen at the bottom of the screen.

First detect event when Tool/Gun with .Equipped event after that u can Disable Backpack CoreGui

local Tool = --Tool

Tool.Equipped:Connect(function()
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
	task.wait(1) -- Time until SetCore back true
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
end)

Not what i’m going for. I want it to unequip the items from the player, wait, and then equip the tool that is being called

All i’ve done so far is this:

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local EquipVal = character:WaitForChild("ToolEquipped")
local CurrentEquippedTool = "None"
local UnequipDelay = 0.5

local function HandleToolSwitch(newToolName)
	if CurrentEquippedTool ~= newToolName then
		print("Player switched from " .. CurrentEquippedTool .. " to " .. newToolName)
		CurrentEquippedTool = newToolName
		EquipVal.Value = newToolName
	end
end

character.ChildAdded:Connect(function(child)
	if child:IsA("Tool") then
		if EquipVal.Value == "None" then
			EquipVal.Value = child.Name
			CurrentEquippedTool = child.Name
		else
			HandleToolSwitch(child.Name)
		end
	end
end)

character.ChildRemoved:Connect(function(child)
	if child:IsA("Tool") then
		if EquipVal.Value == child.Name then
			wait(UnequipDelay)
			if EquipVal.Value == child.Name then
				HandleToolSwitch("None")
				EquipVal.Value = "None"
			end
		end
	end
end)

Can’t think of what to do after this point to make it work the way i want it to