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

my data is not saving and idk why plis help me if you know what is wrong?

this is my code...

Players.PlayerAdded:Connect(leaderbaordFunction)

local r = game.ReplicatedStorage.Click

r.OnServerEvent:Connect(function(player) player.leaderstats.Strenght.Value = player.leaderstats.Strenght.Value + 5 end)

game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player

local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats

local Strenght = Instance.new("IntValue")
Strenght.Name = "Strenght"
Strenght.Parent = leaderstats

local playerUserId = "Player_"..player.UserId

--Load Data

local data
local success, errormessage = pcall(function()
	data = myDataStore:GetAsync(playerUserId)
end)

if success then
	if data then
		Cash.Value = data.Cash
		Strenght.Value = data.Strenght
		-- Load the data from last time you played the game
	end

end

end)

game.Players.PlayerRemoving:Connect(function(player) local playerUserId = "Player_"..player.UserId

local data = {
	Cash = player.leaderstats.Cash.Value;
	Strenght = player.leaderstats.Strenght.Value;
}

local success, errormessage = pcall(function()
	myDataStore:SetAsync(playerUserId, data)
end)

if success then
	print("Data Saved")
	
else
	print("There was an error while saving data	")
	warn(errormessage)
			
end

end)

1 answer

i dont see myDataStore variable so

local myDataStore = game:GetService("DataStoreService"):GetDataStore("StrengthData")

now you have DataStore where you can store things

also try using 2 different datastore on each leaderstats value

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