#Need help with error
37 messages · Page 1 of 1 (latest)
It says "can't store instance in a datastore" that means that you are trying to store an instance (like part, model or folder) which is not allowed. Datastores can only store serializable (to serialize means to convert into a string) data types e.g. strings, numbers, Vectors, CFrames and not-mixed tables which only contain those data types
can you help me fix it?
local DataStoreService = game:GetService("DataStoreService")
local DataSavingScript = DataStoreService:GetDataStore("MyDataStore")
local function saveData(player)
local key = "PlayerData_" .. player.UserId
local success, error = pcall(function()
DataSavingScript:SetAsync(key, player.leaderstats)
end)
if not success then
print("Error saving data for player " .. player.Name .. ": " .. error)
end
end
local function loadData(player)
local key = "PlayerData_" .. player.UserId
local success, data = pcall(function()
return DataSavingScript:GetAsync(key)
end)
if success and data then
player.leaderstats.Value = data.Value
end
end
game.Players.PlayerAdded:Connect(function(player)
loadData(player)
player.CharacterAdded:Connect(function(character)
loadData(player)
end)
player.CharacterRemoving:Connect(function(character)
saveData(player)
end)
player:WaitForChild("leaderstats").Changed:Connect(function()
saveData(player)
end)
end)
this is the script i used
Well you are trying to store a folder
Player.leaderstats
Instead of saving entire leaderstats you can create a table and put data from leaderstats into it then you will be able to store the table
I couldnt send the script as its too long so I used pastebin:
https://pastebin.com/Bzqpw2wc
alternatively I can send it via file
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
what are you tryna store
leaderstats
save the values
I literally generated this script with AI
you could ask AI in ai-help or in the roblox creator hub for free. thats a vary simple script
local leaderstats = -- Path to folder
local data = {}
for _, stInstance in leaderstats:GetChildren() do
data[stInstance.Name] = stInstance.Value
end
dataStore:SetAsync(data)
for example
tho I didnt check if it works
i used script from
ai
i think your script works
nope
there isnt error
but
change player.leaderstats to an actual value and not a folder instance