So, I’ve recently completed my accessory datastore. And when I tested it, the output said that everything was saved. But when I rejoin, the accessory has not been saved and it’s gone. Any help?
Here’s the code for the data store:
local DataStoreService = game:GetService("DataStoreService")
local DataStoreName = DataStoreService:GetDataStore("myDataStore")
local player = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
local DominoValue = Instance.new("BoolValue")
DominoValue.Name = "Domino"
DominoValue.Parent = player
local DominoItem = game.ReplicatedStorage.Hats.Domino
if DominoValue.Value == true then
local Folder = Instance.new("Folder")
Folder.Name = "Hats"
Folder.Parent = Character.Head
local Head = Character.Head
local New_Hat = DominoItem:Clone()
New_Hat.Parent = Folder
New_Hat.Position = Head.Position
local Weld = Instance.new("Weld")
Weld.Parent = New_Hat
Weld.Part0,Weld.Part1 = Head, New_Hat
Weld.C0 = CFrame.new(0,1.4,0)
Weld.C1 = Head.HatAttachment.CFrame
end
end)
local data
local success, errormessage = pcall(function()
data = DataStoreName:GetAsync(player.UserId.."-Hats")
end)
if success then
print("Hats loaded")
else
print("Error")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
DataStoreName:UpdateAsync(player.UserId.."-Hats",function(old)
local newvalue = old
newvalue = player.Domino.Value
return newvalue
end)
end)
if success then
print("Hats have been saved.")
else
warn(errormessage)
end
end)