My inventory code is in serverscriptservice, but the if statement is underlined red, but I don't know what is wrong, I tried, doing then and else after the if statement. I put some * around the if

print("Hello world!")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetDataStore("BackpackSave")

game.Players.PlayerAdded:Connect(function(player)
	pcall(function()
		local tool = dataStore:GetAsyne("User-"..player.UserId)
		if tool then
			for i,v in pairs(tool) do
				local toolFound = game.ReplicatedStorage.Items:FindFirstChild
				***if*** toolFound then
					toolFound:Clone().Parent = player.Backpack
					toolFound:Clone().Parent = player.StarterGear
				end
			end
		end
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	pcall(function()
		local toolsSave = {}
		for i, tool in pairs(player.Backpack:GetChildren()) do
			if tool then 
				table.insert(toolsSave,tool.Name)
			end
		end
		dataStore:SetAsync("User-"..player.UserId,toolsSave)
	end)
end)

5 comments

0

I'm pretty sure you need to do something like if toolFound = true then

0

It still does not work

0

there's a typo in the variable itself. "local toolFound = game.ReplicatedStorage.Items:FindFirstChild()" is what it should be above the if statement

0

still does not work

0

even with both scripts together