Backpack GUI Doesn't Add Tools At First

I am attempting to create a custom backpack system. It works when tools are added using clickdetectors, but not when a team’s tools are cloned when their character is created. The tools are added, but the gui is not. I have tried different wait times like .25, 1, 5 ect which work for me, but not always for others’ who test it. No errors are given. Any solutions?

Script that gives the tools:

local team1Tools = {"Cup", "Pistol", "Donut"}

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		-- wait(.25) works for me here, but not others
		local character = player.Character or player.CharacterAdded:Wait()
		for a,c in pairs(team1Tools) do
			local tool = game.ServerStorage:WaitForChild("Tools")[c]:Clone()
			tool.Parent = player.Backpack
		end	
	end)
end)

LocalScript that creates ui

local player = game.Players.LocalPlayer
local backpack = player.Backpack
local character = player.Character or player.CharacterAdded:Wait() 
local tools = {}
local function tooladded(added)
	if added:IsA("Tool") then
		local new = true
		for i,v in pairs(tools) do
			if added == v then
				new = false
			end
		end
		if new == true then
			table.insert(tools, added)
			new = false
			local ui = player.PlayerGui:WaitForChild("Elements"):WaitForChild("ItemTemplate"):Clone()
			ui.Name = added.Name
			ui.Tool.Image = added.TextureId
			ui.Label.Text = #tools
			ui.Parent = player.PlayerGui:WaitForChild("MainGui"):WaitForChild("Backpack")
		end
	end
end

character.ChildAdded:Connect(tooladded)
backpack.ChildAdded:Connect(tooladded)
1 Like

Are you sure new is true?
Is Elements/ItemTemplate actualy in PlayerGui. Is Visible set to true?

Yeah, as stated it works if I add a tool with a click detector. It also works if I take the tool out of my backpack and put it back in so I think it has to do with the adding the tools before the localscript loads in. Although, the wait needed is unknown.

I found a solution without using wait. It may not be the best solution, but it seems to work from my testing. I added:

for a,c in pairs({backpack, character}) do
	for i,v in pairs(c:GetChildren()) do
		tooladded(v)
	end
end

Directly after the tooladded function which adds the tools to the backpack UI.