hi i m actually create game in roblox but i have a little problem with one of my script, the table didn't want to save. this is my script :
local DataStoreService = game:GetService("DataStoreService")
local TableDataStore = DataStoreService:GetDataStore("Avatar")
game.Players.PlayerAdded:Connect(function(plr)
game.ReplicatedStorage.remote.loaded.OnServerEvent:Connect(function(plr, state)
if state == "atoi" then
local UserIdKey = plr.UserId.. "AvatarData"
local data
local success, errormessage = pcall(function()
data = TableDataStore:GetAsync(UserIdKey)
end)
if data and data[1] then
local cloneColor = game.ReplicatedStorage.remote.Folder.couleur:WaitForChild(data[1]):Clone()
cloneColor.Parent = plr.Character
task.wait()
game.ReplicatedStorage.remote.loaded:FireClient(plr, "cesbon")
else
local cloneColor = game.ReplicatedStorage.remote.Folder.couleur:WaitForChild("Beige"):Clone()
cloneColor.Parent = plr.Character
task.wait()
game.ReplicatedStorage.remote.loaded:FireClient(plr, "cesbon")
print(errormessage)
end
end
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local achar = game.Workspace:WaitForChild(plr.Name):GetDescendants()
local UserIdKey = plr.UserId.. "AvatarData"
local AvatarTable = {}
for _,accessory in ipairs(achar) do
if accessory:IsA("BodyColors") then
table.insert(AvatarTable,1, accessory.Name)
end
end
local success, errormessage = pcall(function()
TableDataStore:SetAsync(UserIdKey,AvatarTable)
end)
if success then
print("save")
else
print(errormessage)
end
end)