#Need help with error

37 messages · Page 1 of 1 (latest)

mellow iris
#

how do i fix this?

runic garden
#

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

mellow iris
#

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

runic garden
#

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

mellow iris
#

tbh idk how to do that

#

can you slide help?

runic garden
hollow quartz
#

what are you tryna store

mellow iris
#

leaderstats

hollow quartz
#

save the values

runic garden
mellow iris
#

to store this

#

for this to save

#

and everything

#

like progress in game

runic garden
# mellow iris

you could ask AI in ai-help or in the roblox creator hub for free. thats a vary simple script

hollow quartz
#
local leaderstats = -- Path to folder
local data = {}

for _, stInstance in leaderstats:GetChildren() do
  data[stInstance.Name] = stInstance.Value
end
dataStore:SetAsync(data)
#

for example

runic garden
mellow iris
#

ai

#

i think your script works

#

nope

#

there isnt error

#

but

runic garden
mellow iris
#

it doesnt save anything

#

@runic garden

runic garden
#

idk

#

ctrl+s then alt+p

solemn glen