Hello, i have problem with save player accessories and here my code:
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("AccessoriesSaver")
game.Players.PlayerAdded:Connect(function(Player)
local Data
local Folder = Instance.new("Folder", Player)
Folder.Name = "Items"
pcall(function()
Data = myDataStore:GetAsync(Player.UserId)
for _, Item in pairs(Data) do
local Value = Instance.new("StringValue", Folder)
Value.Name = Item
end
Player.CharacterAdded:Connect(function()
for i, accessory in pairs(Folder:GetChildren()) do
game.ServerStorage.Accessories[accessory.Name]:Clone().Parent = Player.Character
end
end)
end)
end)
game.ReplicatedStorage.SaveEvent.OnServerEvent:Connect(function(Player)
pcall(function()
local Wear = {}
for _, Item in pairs(Player.Items) do
table.insert(Wear, Item.Name)
end
myDataStore:SetAsync(Player.UserId, Wear)
end)
end)
Try changing it to this script real quick so we can see the error.
game.ReplicatedStorage.SaveEvent.OnServerEvent:Connect(function(Player)
local success, errorMessage = pcall(function()
local Wear = {}
for _, Item in pairs(Player.Items) do
table.insert(Wear, Item.Name)
end
myDataStore:SetAsync(Player.UserId, Wear)
end)
if success then
print("it works woohoo!")
else
error(errorMessage)
end
end)