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

DataStore throttling causing player's to lose their data. Help?

Picture!

So my datastore is throttling, and it's causing some people to lose their data because of it. I only save when a player buys currency or leaves the game.

Here I'm saving their stats when they buy points. Maybe when someone is repeatedly buying points? How should I fix this?

PointsEvent.OnServerEvent:Connect(function(player,asset)
	for i,v in pairs(PointsModule.PointsInfo)do
		if v.Name == asset then
			MS:PromptProductPurchase(player,v.Id)
			MS.ProcessReceipt = function(receiptInfo)
				if player.UserId == receiptInfo.PlayerId then
					if receiptInfo.ProductId == v.Id then
						player:WaitForChild("leaderstats").Points.Value = player:WaitForChild("leaderstats").Points.Value + v.Amount
						wait()
						print("Saved player data!")
						DataStore:SetAsync(player.UserId,player.leaderstats.Points.Value) 
					end
				end
			end
		end
	end
end)

Here I'm getting the data when they join the game. I don't really know why that would cause data loss. I'm including it just in case it does...

game.Players.PlayerAdded:connect(function(Player)
	local ls = Instance.new("IntValue", Player)
	ls.Name = "leaderstats"
	
	local r = Instance.new("StringValue", ls)
	r.Name = "Rank"
	r.Value = Player:GetRoleInGroup(3281134)
	
	local p = Instance.new("IntValue", ls)
	p.Name = "Points"
	p.Value = 0
	
	local data = DataStore:GetAsync(Player.userId)
	if data then
		p.Value = data
	end

end)

Here's where I save the data when they leave the game.

game.Players.PlayerRemoving:Connect(function(Player)
	DataStore:SetAsync(Player.UserId,Player.leaderstats.Points.Value)
	print("Saved "..Player.Name.."'s".." data!")
end)

How would I stop it from throttling? It's causing people to lose their data and it's especially bad when they buy items and it doesn't save...

5 comments

0

On your PlayerAdded, it should be Connect, not connect.

0

Has nothing to do with my problem though lol

0

I know, but it's always good practice to deviate from deprecated code.

0

Anyways you probably are sending too many requests, as the output says.

0

... I know this. I'm asking how do I stop it? I need to obviously get the data when someone joins and save when someone buys an item and when they leave the game.......

1 answer

✓ Accepted answer

###The problem is that data is a table, and needs to be indexed. The value of an IntValue cannot be a table.. Also, the name (aka key) needs to be a string, and you assigned it to an int64.

game:GetService("Players").PlayerAdded:Connect(function(Player)
    local key = "Player_"..Player.UserId -- Needs to be a string, I got you
    local ls = Instance.new("IntValue")
    ls.Name = "leaderstats"
    ls.Parent = Player
 -- The parent argument to Instance.new is deprecated and known to cause latency, assign in another line

    local r = Instance.new("StringValue")
    r.Name = "Rank"
    r.Value = Player:GetRoleInGroup(3281134)
    r.Parent = ls

    local p = Instance.new("IntValue")
    p.Name = "Points"
    p.Value = 0
    p.Parent = ls

    local data = DataStore:GetAsync(key)
    if data then
        p.Value = data[1]
    end
end)

4 comments

0

so how would I save the data? What would be the best method?

0

DataStores are really confusing me

0

You did it right, only you needed to index the data[1], and make the key a string.

0

Oh, alright. Thanks!

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