Serverscript isnt detecting equiped tool

can someone help me fix this issue

local function Save(player: Player)
	local dataKey = 'key_' .. player.UserId
	local data = PlayerData[player] or {}
	local equippedTools = {}


	if player.Character then
		local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
		if humanoid then
			-- Find equipped tools
			for _, tool in ipairs(humanoid:GetChildren()) do
				if tool:IsA("Tool") then
					table.insert(equippedTools, tool.Name)
				end
			end
		end
	end


	if #equippedTools > 0 then
		warn(player, "Equipped tool(s) before leaving:", table.concat(equippedTools, ", "))
		data["EquippedTools"] = equippedTools
	else
		warn(player, "No tools equipped before leaving.")
	end

Equipped tools are usually located in the character.

Tool | Documentation - Roblox Creator Hub

4 Likes

You’re looking in the humanoid, which isn’t where tools are stored. Search in the character like Goatku said.

1 Like
local function Save(player: Player)
local dataKey = 'key_' .. player.UserId
local data = PlayerData[player] or {}
local equippedTools = {}


if player and player.Character then
local char = player.Character or player.CharacterAdded:Wait()
-- Find equipped tools
for _, tool in ipairs(char:GetChildren()) do
if tool:IsA("Tool") then
table.insert(equippedTools, tool.Name)
end
end
end
end


if #equippedTools > 0 then
warn(player, "Equipped tool(s) before leaving:", table.concat(equippedTools, ", "))
data["EquippedTools"] = equippedTools
else
warn(player, "No tools equipped before leaving.")
end