I want 2 Stats scripts but the second one doesn't work

So i want 2 Stats scripts but the second one doesn’t work I’ll show the second Stat script the first is the same but with SaveData instead of SaveData1 am I doing something wrong

local Data = game:GetService("DataStoreService"):GetDataStore("SaveData1") 
game.Players.PlayerAdded:Connect(function(plr)

	local s = Instance.new("Folder",plr)
	s.Name = "Stats" 	

	local Rock = Instance.new("NumberValue",s) 
	Rock.Name = "Rock"
	Rock.Value = 0


	local succ2,err2 = pcall(function()
		dataload = Data:GetAsync(tostring(plr.UserId))	
	end)

	if dataload and succ2 then
		Rock.Value = dataload[1] or 0
		

	else
		print(err2)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local succ,err = pcall(function()
		Data:SetAsync(tostring(plr.UserId),{
			plr.Stats.Rock.Value,

			

		})
	end)
	if succ then
		print("Saved Data succesfully")
	else
		print(err)
	end
end)

Can someone also explain me how to use the ´´´ right

Like that :

´´´lua
You script here
´´´

But sorry Idk why your script bugs

Can you elaborate on what you mean by “doesn’t work”?

i am using

´´´lua

´´´
but it still doesnt work am a still doing something wrong?

well if i try to play it say Nil

There’s nothing that would make an error, so nil as the printed output is expected.

so it isn’t an error and it should work good?

That is correct, but then and again, you also don’t check for anything that would make it work. For example, if you got the nil error from

if dataload and succ2 then
	Rock.Value = dataload[1] or 0
	

else
	print(err2)
end

then that could also mean that the data you are getting from the DataStore just doesn’t exist.

you sure these are backticks?
if they are then idk why it wouldn’t work

1 Like

thx for explaining it to me now i undderstand it, thx for your time