#data store isnt working
1 messages · Page 1 of 1 (latest)
local dataStoreService = game:GetService("DataStoreService")
local leaderstats = dataStoreService:GetDataStore("leaderstats")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = folder
local data
local success, err = pcall(function()
data = leaderstats:GetAsync(player.UserId)
if not data then
data = {0}
end
end)
coins.Value = data[1]
end)
game.Players.PlayerRemoving:Connect(function(player)
local coins = player:FindFirstChild("leaderstats"):FindFirstChild("Coins")
leaderstats:SetAsync(player.UserId, {coins.Value})
end)```
any errors?
and
wait
nvm
any errors tho?
well
so first i get this when i close
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key
and i think thats it
huhhh
ok wtf did u do
how did u manage that
not sure
wait so i have some more code
game.Players.PlayerAdded:Connect(petsModule.AddPlayer)
game.Players.PlayerRemoving:Connect(petsModule.RemovePlayer)```
that does this:
local module = {}
local dataStoreService = game:GetService("DataStoreService")
local leaderstats = dataStoreService:GetDataStore("leaderstats")
module.AddPlayer = function(Player: Player)
local playerFolder = Instance.new("Folder")
playerFolder.Name = "OwnedPets"
playerFolder.Parent = Player
local playerFolder2 = Instance.new("Folder")
playerFolder2.Name = "EquippedPets"
playerFolder2.Parent = Player
local configurationFolder = Instance.new("Folder")
configurationFolder.Name = "Configuration"
configurationFolder.Parent = Player
local hatchingValue = Instance.new("BoolValue")
hatchingValue.Name = "Hatching"
hatchingValue.Parent = configurationFolder
hatchingValue.Value = false
local data
local success, error = pcall(function()
data = leaderstats:GetAsync(Player.UserId)
end)
if not data or type(data) ~= "table" then
data = {}
end
data["OwnedPets"] = data["OwnedPets"] or {}
data["EquippedPets"] = data["EquippedPets"] or {}
if error then
warn(error)
end
for i, v in pairs(data["OwnedPets"]) do
local tag = Instance.new("IntValue")
tag.Name = v
tag.Parent = playerFolder
end
for i, v in pairs(data["EquippedPets"]) do
local tag = Instance.new("IntValue")
tag.Name = v
tag.Parent = playerFolder2
end
end
module.RemovePlayer = function(Player: Player)
local data = {}
local owned = {}
local equipped = {}
for i, v in pairs(Player.OwnedPets:GetChildren()) do
table.insert(owned, v.Name)
end
for i, v in pairs(Player.EquippedPets:GetChildren()) do
table.insert(equipped, v.Name)
end
data["OwnedPets"] = owned
data["EquippedPets"] = equipped
leaderstats:SetAsync(Player.UserId, data)
end
return module
@unique moat but thats it
so im not sure how that works
print data ig?
or smth
idk keep printing shit
actually wait
print(data[1])
okay when i make it?
and save it ?
ill do this
local module = {}
local dataStoreService = game:GetService("DataStoreService")
local leaderstats = dataStoreService:GetDataStore("leaderstats")
module.AddPlayer = function(Player: Player)
local playerFolder = Instance.new("Folder")
playerFolder.Name = "OwnedPets"
playerFolder.Parent = Player
local playerFolder2 = Instance.new("Folder")
playerFolder2.Name = "EquippedPets"
playerFolder2.Parent = Player
local configurationFolder = Instance.new("Folder")
configurationFolder.Name = "Configuration"
configurationFolder.Parent = Player
local hatchingValue = Instance.new("BoolValue")
hatchingValue.Name = "Hatching"
hatchingValue.Parent = configurationFolder
hatchingValue.Value = false
local data
local success, error = pcall(function()
data = leaderstats:GetAsync(Player.UserId)
end)
if not data or type(data) ~= "table" then
data = {}
end
data["OwnedPets"] = data["OwnedPets"] or {}
data["EquippedPets"] = data["EquippedPets"] or {}
if error then
warn(error)
end
for i, v in pairs(data["OwnedPets"]) do
local tag = Instance.new("IntValue")
tag.Name = v
tag.Parent = playerFolder
end
for i, v in pairs(data["EquippedPets"]) do
local tag = Instance.new("IntValue")
tag.Name = v
tag.Parent = playerFolder2
end
print(data[1])
end
module.RemovePlayer = function(Player: Player)
local data = {}
local owned = {}
local equipped = {}
for i, v in pairs(Player.OwnedPets:GetChildren()) do
table.insert(owned, v.Name)
end
for i, v in pairs(Player.EquippedPets:GetChildren()) do
table.insert(equipped, v.Name)
end
data["OwnedPets"] = owned
data["EquippedPets"] = equipped
leaderstats:SetAsync(Player.UserId, data)
print(data[1])
end
return module
just print anywhere
i get nil
and nil again
this is when i dont have any data rn anyway
huhh
at this point
just get
profileservice/store
u are better of using it anyways
community made datastore module
prob better then u would ever make or need
where do i get
** You are now Level 8! **