Here is the the code for the datastore below. (I am new to datastores so I went off of a tutorial with some changes). I also changed the leader.Name to "leaderstats" from "statStorage" because I couldn't see the Credit Number. I wanted it to be privately displayed on a Gui (which is done), but I will have to change "leaderstats" back to "statStorage". Could the name change be the reason why, and if so, would changing the datastore name fix it(creating a new one)? Thanks!

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("TrustCurrency")
print("step1")

game.Players.PlayerAdded:connect(function(player)
	local leader = Instance.new("Folder",player)
	leader.Name = "leaderstats"
	print("step2")
	local Credits = Instance.new("IntValue",leader)
	Credits.Name = "Credits"
	print("step3")
	Credits.Value = ds1:GetAsync(player.userId) or 100
	ds1:SetAsync(player.userId,Credits.Value)
	print("step4")
	wait(.2)
	print("Initial Load Complete")

	Credits.Changed:connect(function()
		print("Saving Data")
		ds1:SetAsync(player.userId,Credits.Value)
		print("Saved "..player.userId.."'s Credit Balance of "..Credits.Value)
	end)
end)

--Test Section--

--Used to test for data saving and such--

local creditpool = game.Workspace.creditpole

creditpool.Touched:connect(function(player)
local stat = player.leader.Credits
  stat.Value = stat.Value + 5
print("5 Credits Added")
end
end)


--End Test Section--

local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("TrustCurrency")


game.Players.PlayerRemoving:connect(function(player)
		ds1:SetAsync(player.userId,player.leaderstats.Credits.Value)
	print("Saved "..player.userId.."'s Credit Balance of "..player.StatStorage.Credits.Value)
end)



game.OnClose = function()
	print("Closing")
wait(15) 
	print("Closed")
	wait(1)
end

2 comments

1

May I know the error specifically? And also what is not working right(Loading,Saving)?

0

The script works up until line 13, but then shows this:  share.pho.to/AENyv