Tool disappearing mysteriously?

I have this script (pseudo) that runs after player joins and datastore has fully loaded:

function LoadCharacter(player)
	
	-- added
	player.CharacterAdded:connect(function(character)

       -- add weapon
		local weapon = Weapons[weapon]:Clone()
        weapon.Name = "Weapon"
		weapon.Parent = character
		spawn(function()
			local start = tick()
			while wait() and (tick() - start) < 4 do
				local w = character:FindFirstChild("Weapon")
				if not w then
					local msg = Instance.new("Hint",workspace)
					msg.Text = "Weapon not loaded: " .. data.inventory.weapons[using][1] .. "_" .. tick() - start
					break
				end
			end
		end)
    end)
    player:LoadCharacter() 
end

For some reason, when the players first joins, they sometimes (3 out of ~4000 sessions) have no weapon. According to my “hint” section, the weapon does get parented, but it disappears after ~1.5-3.0 seconds. My theory was that its a bug where the weld sometimes doesn’t get created since it happens so rarely. But I’ve searched and no one seems to have this problem (as of late) and manually creating the weld didn’t solve it either.

So I decided to post here, wondering if me parenting the tool like this is bad practice? Maybe the character hasn’t fully loaded on “CharacterAdded” and it “resets” the children after I parent? Or something. I don’t know what to do apart from creating a loop that reparents the weapon whenever it disappears …

2 Likes

Have you tried doing:

local humanoid = -- get the humanoid
local tool = -- get the tool
Humanoid:EquipTool(tool)
5 Likes

It’s useful information to include which rig type(s) this happens with. Generally, I would suggest using CharacterAppearanceLoaded instead of CharacterAdded for something like this.

As well, use the method @Dev_Ryan said on giving the character the tool. It’s better to use an official method of equipping the tool rather than parenting the tool to the character and crossing your fingers.

3 Likes

Apparently pressing backspace puts the tool back in the backpack. Didn’t notice this since I have disabled backpack. Thought CanBeDropped prevented this. My bad!

1 Like

Mark as solution?

1 Like