i might have to ask for the rbxl file atm.
since the pcall(function() isn’t returning any error everything shall be fine.
as i expected The Folder is always empty
you’re trying to save childrens from a folder which is always empty thats why its not working.
Ah, well okay. Based on other posts from the forum I thought that this code would create a stringvalue with the name of the accessory and parent it to the folder. I feel really dumb I’m sorry. Thank you for helping with what you could.
local success,errormsg = pcall(function()
Data = DataStore:GetAsync(Player.UserId.."-Data")
for _,Item in pairs(Data) do
print(Item)
local Value = Instance.new("StringValue",AccessoriesFolder)
Value.Name = Item
end
end)
no everyone makes mistakes no worries lol
add a script in serverscriptservice and :
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char.ChildAdded:Connect(function(Accessory)
if Accessory:IsA("Accessory") then
Accessory:Clone().Parent = plr:FindFirstChild("PlayerAccessories")
end
end)
end)
end)
this will clone the accessory that gets added to the player character and when he leave & rejoins it will convert that accessory to a string value with the name of the accessory.
Oh my gosh!!! It printed the name of the accessory! But the accessory still did not save. I believe the DataStore has now found the accessory but it is not putting it back on the player. I am not sure why?
as i said i tested it myself, and everything worked for me.
also add an if statement here
for _,item in pairs(Data) do
if item then
local Value= Instance.new("StringValue",AccessoriesFolder)
Value.Name = item
end
end)
do you want the player to equip the accessory when he joins the game?
I want the player to be wearing the accessory they had chose before they left the game. Does that make sense? That’s why I’m saving the Accessory in the datastore so it can be put back onto the player when they rejoin the game. Say they chose a hair, and left the game. If they join back, I want that hair to still be on their character.
unfortunately, you can’t save instances in datastores so you have to put its properties.
but hold up
This code was supposed to put the accessory back onto the player once they’ve joined back
Player.CharacterAdded:Connect(function()
for i,accessory in pairs(AccessoriesFolder:GetChildren()) do
game.ServerStorage.AllAccessories[accessory.Name]:Clone().Parent = Player.Character
end
end)
Player.CharacterAdded:Connect(function(char)
for _,accessory in pairs(AccessoriesFolder:GetChildren()) do
if game.ServerStorage.AllAccessories:FindFirstChild(accessory.Name) then
game.ServerStorage.AllAccessories:FindFirstChild(accessory.Name):Clone().Parent = char
end
end
end)
and change that recent script to this
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char.ChildAdded:Connect(function(Accessory)
if Accessory:IsA("Accessory") then
Accessory:ClearAllChildren()
Accessory:Clone().Parent = plr:FindFirstChild("PlayerAccessories")
end
end)
end)
end)
I tried it and it did not work. I’m not sure what I am doing wrong?
Does it work for you?
limitttt
change this
to this
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char.ChildAdded:Connect(function(Accessory)
if Accessory:IsA("Accessory") then
plr:FindFirstChild("PlayerAccessories"):ClearAllChildren()
Accessory:Clone().Parent = plr:FindFirstChild("PlayerAccessories")
end
end)
end)
end)
and btw it works only when player resets thats must likely because the startercharacter that you put in there.
Oh my, thank you so much!! It works! I’m a little sad that it only works when reset, but it’s okay. Thank you again!
np, but dw ima consider fixing it for you tommorow.