Datastore script not working?

Here is the script:

local ds = game:GetService("DataStoreService")
local rpDS = ds:GetDataStore("RPname")
local cashDS = ds:GetDataStore("CashDS")

wait(1)
game.Players.PlayerAdded:Connect(function(plr)
	plr.RPname.Value = rpDS:GetAsync(plr.UserId) or plr.Name
	plr.leaderstats.Cash.Value = cashDS:GetAsync(plr.UserId) or 200
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local saved, msg =  pcall(function()
		cashDS:SetAsync(plr.UserId, plr.Leaderstats.Cash.Value)
	end)
	if not saved then
		for i = 1, 10 do
			warn("Failed to save; attempt " .. i .. ". Error: " .. msg)
			wait(5)
			cashDS:SetAsync(plr.UserId, plr.leaderstats.Cash.Value)
		end
	end
	
	local saved, msg =  pcall(function()
		rpDS:SetAsync(plr.UserId, plr.RPname.Value)
	end)
	if not saved then
		for i = 1, 10 do
			warn("Failed to save; attempt " .. i .. ". Error: " .. msg)
			wait(5)
			rpDS:SetAsync(plr.UserId, plr.Character.Head.RP.TextLabel.Text)
		end
	end
end)

Server script in server script service.
No errors.

Any and all help appreciated. :smiley:

1 Like

Did you turn on the API service?

you should really store the other in a string and the other in a string or else it will override

Yes. :roll_eyes:

smh smh smh

??
The other in a string?
And the other in a string?

Would love a deeper explanation.

1 Like

probably

local ds = game:GetService("DataStoreService")
local rpDS = ds:GetDataStore("RPname")
local cashDS = ds:GetDataStore("CashDS")

wait(1)
game.Players.PlayerAdded:Connect(function(plr)
	plr.RPname.Value = rpDS:GetAsync("Text-"..plr.UserId) or 0
	plr.leaderstats.Cash.Value = cashDS:GetAsync("Cash-"..plr.UserId) or 0
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local saved, msg =  pcall(function()
		cashDS:SetAsync("Cash-"..plr.UserId, plr.leaderstats.Cash.Value)
	end)
	if not saved then
		for i = 1, 10 do
			warn("Failed to save; attempt " .. i .. ". Error: " .. msg)
			wait(5)
			cashDS:SetAsync("Cash-"..plr.UserId, plr.leaderstats.Cash.Value)
		end
	end
	
	local saved, msg =  pcall(function()
		rpDS:SetAsync("Text-"..plr.UserId, plr.Character.Head.RP.TextLabel.Text)
	end)
	if not saved then
		for i = 1, 10 do
			warn("Failed to save; attempt " .. i .. ". Error: " .. msg)
			wait(5)
			rpDS:SetAsync("Text-"..plr.UserId, plr.Character.Head.RP.TextLabel.Text)
		end
	end
end)

the reason why it’s 0 because if its 200 user id and above but how about the users who are below that id cant load their data

1 Like

Yea, definitely not the issue?
The player.UserId argument is to find the store later on?

1 Like

yes it is

30chars

And very not so efficient to use 2 DataStores

True. I should probably fix that.

1 Like