Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

A stat keeps disappearing, any solution?

So, i have these two codes:

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("ChestsSaveSystem")
	

game.Players.PlayerAdded:connect(function(player)
 local leader = player:FindFirstChild("leaderstats")
 local Chests = Instance.new("IntValue",leader)
 Chests.Name = "Chests"
 Chests.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Chests.Value)
 Chests.Changed:connect(function()
  ds:SetAsync(player.UserId, Chests.Value)
 end)
end)



game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.leaderstats.Chests.Value)
end)
local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CoinSaveSystem")

game.Players.PlayerAdded:connect(function(player)
 local leader = Instance.new("Folder",player)
 leader.Name = "leaderstats"
 local Coins = Instance.new("IntValue",leader)
 Coins.Name = "Coins"
 Coins.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Coins.Value)
 Coins.Changed:connect(function()
  ds:SetAsync(player.UserId, Coins.Value)
 end)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.leaderstats.Coins.Value)
end)

and everytime I try testing my game, the Chest stat just disappears and I havent found any solution to that. I have also got 2 output messages: "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests." and "Chests is not a valid member of Folder." Please, help :c

1 answer

first script starting line 5: you didn't make a leaderstat, instead, you tried to find it which is nonexistent. And publish your game if you haven't for it to be fully functional

game.Players.PlayerAdded:connect(function(player)
 local leader = Instance.new("Folder",player)
 local Chests = Instance.new("IntValue",leader)
 Chests.Name = "Chests"
 Chests.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Chests.Value)
 Chests.Changed:connect(function()
  ds:SetAsync(player.UserId, Chests.Value)
 end)
end)

2 comments

0

Already tried doing that, it doesn't work. An error pops up and the other stat wont appear. Isn't there a way to make a single script with both stats?

0

Ok, solved it by re-making the leaderstat script and making a new data-store script! Thanks anyways!

This discussion is preserved as it was. New answers, comments, and votes are closed.