I am making a cosmetic system and it won’t save it to the datastore.
Although my banning system works perfectly.
Banning system:
if target.UserId ~= 129324589 then
local reason = 'Banned.'
if args[2] ~= nil then
for thenum,i in pairs(args) do
if thenum ~= 1 then
reason = reason .. ' ' .. i
end
end
end
local id = target.UserId
target:Kick(reason)
datastore:SetAsync(tostring(id) .. 'Banned', {currentlyBanned = true, Reason = reason})
Cosmetic Datastore:
local dt = game:GetService("DataStoreService")
local storage = dt:GetDataStore('PlrCosmetics')
game:GetService("Players").PlayerAdded:Connect(function(plr)
local list = script:WaitForChild("CosmeticList"):Clone()
list.Parent = plr
list.Name = 'PlayerCosmetics'
local datastore = storage:GetAsync(plr.UserId .. 'Cosmetics')
for _,value in pairs(datastore) do
if list:FindFirstChild(value[1]) ~= nil then
list:FindFirstChild(value[1]).Value = value[2]
end
end
end)
game:GetService("Players").PlayerRemoving:Connect(function(plr)
local list = plr:WaitForChild("PlayerCosmetics")
local itemList = {}
for _,i in pairs(list:GetChildren()) do
if i:IsA("BoolValue") or i:IsA("StringValue") then
local newTable = {}
table.insert(itemList, newTable)
table.insert(newTable, 1, i.Name)
table.insert(newTable, 2, i.Value)
end
end
storage:SetAsync(plr.UserId .. 'Cosmetics', itemList)
end)