I have a game pass in my game that gives you a tool, but it doesn't work unless you backspace it and pick it back up. Any way to fix this?

Error: Handle is not a valid member of Tool

No errors with Tool script

Once backspaced it works fine

local function WaitForChild(parent, childName)
	assert(parent, "ERROR: WaitForChild: parent is nil")
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end
local GamePassService = game:GetService('GamePassService')
local PlayersService = game:GetService('Players')
local InsertService = game:GetService('InsertService')
local LightingService = game:GetService('Lighting')
local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ToolAssetsToLoad = WaitForChild(script, 'ToolAssetsToLoad')
local AdminTools = LightingService:FindFirstChild('AdminTools')
local function CloneAdminTools(target)
	for _, tool in pairs(AdminTools:GetChildren()) do
		local toolClone = tool:Clone()
		toolClone.Parent = target
	end
end
local function OnPlayerAdded(player)
	if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
		local starterGear = WaitForChild(player, 'StarterGear')
		CloneAdminTools(starterGear)
		if player.Character then
			local backpack = WaitForChild(player, 'Backpack')
			CloneAdminTools(backpack)
		end
	end
end
if not AdminTools then
	AdminTools = Instance.new('Model')
	AdminTools.Name = 'AdminTools'
	for _, intObject in pairs(ToolAssetsToLoad:GetChildren()) do
		if intObject and intObject:IsA('IntValue') and intObject.Value then
			local assetModel = InsertService:LoadAsset(intObject.Value)
			if assetModel then
				local asset = assetModel:GetChildren()[1]
				if asset then
					asset.Parent = AdminTools
				end
			end
		end
	end
	AdminTools.Parent = LightingService
end
PlayersService.PlayerAdded:connect(OnPlayerAdded)

4 comments

0

You should include the relevant code. Normally, this would not happen. The problem is a result of your particular configuration. Is there any error occuring? Have you done debugging? Does the script running the tool not run at all? Do some of its events not run? (please edit your post to address these)

0

Just did, sorry about that.

0

Include the code too!

0

Yes, please include the code too. Many things can generate that error, making this thread too broad to solve.