Store player's tools in ReplicatedStorage

Hey there, I’m trying to store a player’s tools in ReplicatedStorage when they leave a zone. I’m using ZonePlus and a remote event.

RepStorage.events.UnequipTools.OnServerEvent:Connect(function(player)
	local PlayerTools = player.Character:FindFirstChildWhichIsA("Tool"):GetChildren()
	local PlayerBackpackTools = player.Backpack:GetChildren()
	for i, v in pairs(PlayerBackpackTools, PlayerTools) do
		v.Parent = RepStorage
	end
end)

I’m not sure how to loop through these two variables at the same time. Any help will be appreciated.

you can use 2 loops

RepStorage.events.UnequipTools.OnServerEvent:Connect(function(player)
	local PlayerTools = player.Character:FindFirstChildWhichIsA("Tool"):GetChildren()
	local PlayerBackpackTools = player.Backpack:GetChildren()
	for i, v in pairs(PlayerBackpackTools) do
		v.Parent = RepStorage
	end
	for i, v in pairs(PlayerTools) do
		v.Parent = RepStorage
	end
end)

The problem with doing that is that if I don’t have a tool in my backpack/equipped it will error and the code wouldn’t run.

Issue solved!

I created two functions - one looped through the player’s backpack, the other looped through the player’s character.

if player.Backpack:FindFirstChildWhichIsA("Tool") then
		BackpackTools()
	end
	
	if player.Character:FindFirstChildWhichIsA("Tool") then
		CharacterTools()
	end

Using this code it checked if it found a tool in either of and if it did, it ran that function.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.