How can I check a players most recently equipped tool?

Okay so I have a custom tool drop system for my game and there is one small issue.
binding backspace
I could very easily just bind a different key but backspace is preferred as it’s the default drop key.

Basically you press backspace and it drops the tool you are holding. However backspace also puts the tool back into your backpack. So I can’t check if the tool is equipped when the key is pressed.
if I do something like this.

tool.Unequipped:Connect(function()
	recentlyequipped = true
	wait(.01)
	recentlyequipped = false
end)

and wait a small amount of time prior to it being unequipped to check if the tool is equipped it works but players can trigger anti-cheat by just quickly selecting 2 different items and dropping one.

Whats the best way to check a players recently equipped tool?

You can make an object value, and every time you equip a tool, you can set the object value’s value to the tool. Which will get you an efficient way to get the player’s recently equipped tool.

local ov = script.ObjectValue
tool.Equipped:Connect(function()
	ov.Value = tool
end)
2 Likes

U can use an object value or an attribute in the players character and listen to .ChildAdded on the char and if it’s a tool set the value or attribute to the tool. Or you could use the method what Collin said, both work pretty much the same but the checking is slightly different