Edit: Sorry For Scam Title, I Accidently Typed It, I Fixed It Already, Sorry.
I Am Making Clothing Data Store So I Don’t Need To Equip Clothing Again After I Leaves, Actually I Am Begginer So I Am Making It With Data Store Tutorial.
Then, I Got Error Called "Attempt to index nil with number, line 37’
Script
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("ClothingSave")
local function SaveClothing(player)
local character = player.Character or player.CharacterAdded:Wait()
local TableToSave = {
character:WaitForChild("Shirt").ShirtTemplate,
character:WaitForChild("Pants").PantsTemplate
}
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, TableToSave)
end)
if success then
print("Data has been saved!")
else
print("Data hasn't been saved!")
warn(err)
end
end
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local ShirtId = character:WaitForChild("Shirt").ShirtTemplate
local PantsId = character:WaitForChild("Pants").PantsTemplate
local data
local success, err = pcall(function()
data = dataStore:GetAsync(player.UserId)
end)
if success then
ShirtId = data[1]
PantsId = data[2]
else
print("The player has no data!")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
SaveClothing(player)
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
SaveClothing(player)
end
end)
If Possible, Please Explain Why This Error Appear.