I did what you said, added in “print(Item.Name)” and it did not print. (“Success” and “Successfully Saved Data Store” were both printed though.)
Ru sure Player.Items exist? [Char Limits]
I mentioned earlier that I had to change “Player.Items” to “Player.PlayerAccessories” because “Items” was not the right name. “PlayerAccessories” was the right name. Yes, it exists. It is the folder that is created when the player joins and is parented to the Player.
then how is it not printing its children?
also when you get the hair inside the game, can you check for Player.Items? like if its empty/not empty?
I’m not sure, don’t know :’/
limittt
I checked. When joined, I’m able to find the PlayerAccessories folder, however when putting on a hair nothing is added to the folder.
what about Player.Items?
[Char Limit]
its most likely because Player.Items is empty.
Aaa I’m sorry I think I got you confused. I am very sorry. It is Player.PlayerAccessories. Player.Items does not exist, but Player.PlayerAccessories does exist. I had to change Player.Items to Player.PlayerAccessories. Does that make sense?
yeah you have to change
for _, Item in pairs(Player.Items:GetChildren()) do
table.insert(Accessories, Item.Name)
end
to
for _, Item in pairs(Player.PlayerAccessories:GetChildren()) do
table.insert(Accessories, Item.Name)
end
Yes, I did that already. I changed Player.Items to Player.PlayerAccessories. I think the issue here is that the stringvalues are not being created once a player has put on an accessory. I’m not yet very familiar with DataStores so I’m not very sure if it is working right, but a stringvalue is supposed to be created with the name of the player’s accessory and parented to the PlayerAccessories folder. This is the part that should be doing that. Maybe it is not right
local success,errormsg = pcall(function()
Data = DataStore:GetAsync(Player.UserId)
for _,Item in pairs(Data) do
print(Item)
local Value = Instance.new("StringValue", AccessoriesFolder)
Value.Name = Item
end
end)
that wouldn’t be related to datastore.
here in the datastore we’re saving the data when the player leaves.
and we’re recieving it back when the players joins back.
Yes yes I know. I’m just saying I believe that part is the issue that is causing the accessories to not save. I think the accessories aren’t saving because a value is supposed to be created with the accessory name but that is not happening for some reason
is Item printing now?
[Char Limits]
No, it is not printing
limitttt
can you try this?
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DATA")
game.Players.PlayerRemoving:Connect(function(Player)
local success,errormsg = pcall(function()
local Accessories = {}
for _, Item in pairs(Player.Items:GetChildren()) do
table.insert(Accessories, Item.Name)
end
DataStore:SetAsync(Player.UserId.."-Data", Accessories)
end)
if success then
print("Successfully Saved Data Store!")
else
warn(errormsg)
end)
game.Players.PlayerAdded:Connect(function(Player)
local Data
local AccessoriesFolder = Instance.new("Folder")
AccessoriesFolder.Name = "PlayerAccessories"
AccessoriesFolder.Parent = Player
local success,errormsg = pcall(function()
Data = DataStore:GetAsync(Player.UserId.."-Data")
for _,item in pairs(Data) do
local Value= Instance.new("StringValue",AccessoriesFolder)
Value.Name = item
end
end)
if success then
print("Success")
else
warn(errormsg)
Player.CharacterAdded:Connect(function()
for i, accessory in pairs(AccessoriesFolder:GetChildren()) do
game.ServerStorage.AllAccessories[accessory.Name]:Clone().Parent = Player.Character
end
end)
end)
I did what you said to try. The accessories still did not save. Tested both in Studio and In-Game.
remove the white spaces in
table.insert(Accessories, Item.Name)
and
DataStore:SetAsync(Player.UserId, Accessories)
Just did that, still not working. :’( I’m really sorry for the inconvenience this has caused.