Why does my tool delete after a couple of seconds in game but not in studio?

I’m beyond confused right now.

I am trying to equip an item with my own custom quick inventory, so whenever the player clicks on an item in the inventory the item is supposed to be equipped on the player. There aren’t any problems in studio, neither are there any problems when I’m in-game by myself. The problem is that when I’m in-game with other players the tool is only equipped for a random amount of seconds before it unequips or deletes or something. I have seen other posts talk about this and mention that its due to the code not being filtering enabled. However, the tool gets loaded in and parents to the character from the server. Is it due to the item coming from the player’s backpack? How do I actually equip the item then?

StarterPlayerScripts

function gadget_select:DeselectSlot(slot)
	
	print("deselecting slot")
	
	for i,v in pairs(slots) do
		v.BorderColor3 = default_color
	end
	
	if not slot then
		--hum:UnequipTools()
		attach_tool:FireServer(nil)
	else
		-- idk yet
	end

	current_equipped_slot = nil

	infoTxt.Text = ""
	infoUI.Visible = false

end

function gadget_select:SelectSlot(slot)
	local key = slot
	local id
	
	print("selecting slot")
	
	if typeof(slot) == "string" then
		key = slots[slot]
		id = currentIDs[slot].Value
	else
		id = currentIDs[key.Name].Value
	end
	
	if id and id ~= 0 then
		
		self:DeselectSlot()
		local item = backpack[id] or char[id]
		local item_info = item.item_info
		
		for i,v in pairs(slots)do
			if v ~= key then
				v.BorderColor3 = default_color
			else
				current_equipped_slot = v.Name
				v.BorderColor3 = selected_color
				
			end
		end
		
		infoTxt.Text = item_info.gadget_directions.Value
		infoUI.Visible = true
		
		--hum:EquipTool(item)
		attach_tool_event:FireServer(item)
	end
end

ServerScriptService

attachToolEvent.OnServerEvent:Connect(function(plr, item)
	local char = plr.Character
	local hum = char.Humanoid
	
	if not item then
		print("removing item")
		hum:UnequipTools()
	else
		item.Parent = char
		print("adding item")
		hum:EquipTool(item)
	end
end)
3 Likes

a few things to mention here
if im wrong about any of this anyone can feel free to correct me
#1 or #2 may be causing your problem

  1. you shouldn’t need to fire a remote to equip tools. if the tools are in the backpack just use humanoid:equiptool and humanoid:unequiptools locally
  2. don’t parent the tool to the character. just use humanoid:equiptool
  3. that server script, if you intend to keep using it, does not have proper sanity checks for the tools, which means bad actors could equip tools that they’re not supposed to equip
1 Like

I assumed that I could equip a tool locally with :equipTool, but the tool was only visible for the client and never for the server or other players for some reason. It was also the case when I didn’t parent the tool to the character manually, it was only vsible on the client but not the server.

And about the sanity checking, I’m still a little confused on how I can actually ‘verify’ a tool.

Okay I think I found the problem. The item is in the player’s backpack only on the client, but not the server.

2 Likes