I have been practicing a lot of programming and right now I am doing datastores. I don't know what I am doing wrong but it won't save.

Here is my code:

local DSS = game:GetService("DataStoreService")
local ScoreSave = DSS:GetDataStore("ScoreSave")

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder", plr)
	leaderstats.Name = "leaderstats"
	
	local Score = Instance.new("IntValue", leaderstats)
	Score.Name = "Score"
	Score.Value = 100
	
	local SavedScored
	local success, err = pcall(function()
		SavedScored = ScoreSave:GetAsync(plr.UserId.."-Score")
	end)
	if success then
		Score.Value = SavedScored
	else
		warn(err)
	end
	
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, err = pcall(function()
		ScoreSave:SetAsync(plr.UserId.."-Score", plr.leaderstats.Score.Value)
	end)
	if success then
		print("Success")
	else
		warn(err)
	end
end)

I hope you can find what I am doing wrong.

5 comments

0

Did you go to Alvin's tutorial?

0

he probably is

0

make sure api services are enabled

0

I did it mostly from prior knowledge and used the roblox api for guidance. And yes, my api services are enabled