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

[SOLVED] My datastore doesnt work for some reason? Pcall keeps finding an error

I'm making a leaderboard for the amount of robux someone has donated to my game but there is an error. The pcall keeps going to errormessage for some reason. If the solution is easy, pls don't roast me, I'm still trying to learn data stores. If you have any questions, feel free to ask!

local Dataservice = game:GetService("DataStoreService")
local DonationStats = Dataservice:GetChildren("DonationStats")


game.Players.PlayerAdded:Connect(function(plr)
	local Leaderstats = Instance.new("Folder", plr)
	Leaderstats.Name = "leaderstats"
	
	local Dono = Instance.new("IntValue", Leaderstats)
	Dono.Name = "Donation"
	
	local plrId = "Player_"..plr.UserId
	
	local data
	
	local success, errormessage = pcall(function()
		 data = DonationStats:GetAsync(plrId)
	end)
	
	if success then
		Dono.Value = data
	end
 
end)


game.Players.PlayerRemoving:Connect(function(Removed)
	local PlrId = "Player_"..Removed.UserId
	
	local data = Removed.leaderstats.Donation
	
	local success, errormessage = pcall(function()
		DonationStats:SetAsync(PlrId, data.Value)
	end)
	
	if success then
		print("Saved data for"..Removed.Name)
	end
	
	if errormessage then
		print("Data Save had an error for"..Removed.Name)
		print(data.Value)
	end
	
end)

1 answer

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