Datastores being broken

local wins = temporalData[plr.UserId].Wins or 0
Wins.Value = wins
1 Like

So, if i want coins i do

local wins = temporalData[plr.UserId].Wins or 0
Wins.Value = wins
local coins = temporalData[plr.UserId].Coins or 0
Coins.Value = coins
1 Like

Yes, this should be it
Don’t change anything in player removed connection, should work fine

1 Like

Alright, so do i just delete my old datastore and add everything in?

1 Like

Yes, also you can store abilities like this:

if temporalData[plr.UserId].Abilities == nil then
   temporalData[plr.UserId].Abilities = {}
end

and set abilities:

local ability1 = temporalData[plr.UserId].Abilities.Boost
if ability1 == nil then
   ability1 = false
end
BoostAbility.Value = ability1
1 Like
game.Players.PlayerAdded:Connect(function(plr)
      temporalData[plr.UserId] = ds:GetAsync(plr.UserId)
      --make all your bool values here
local wins = temporalData[plr.UserId].Wins or 0
local coins = temporalData[plr.UserId].Coins or 0
      wins.Value = Wins
      coins.Value = Coins
Wins.Changed:Connect(function()
   temporalData[plr.UserId].Wins = Wins.Value
end)
Coins.Changed:Connect(function()
   temporalData[plr.UserId].Coins = Coins.Value
end)
game.Players.PlayerRemoving:Connect(function(plr)
      --Save it to one data store
      ds:SetAsync(player.UserId, temporalData[plr.UserId])
      temporalData[plr.UserId] = nil
end)

This good?
EDIT: Ok, so like this now?

1 Like

To save space you can store numbers like this:

local wins = temporalData[plr.UserId].Wins or 0
local coins = temporalData[plr.UserId].Coins or 0

And make sure letter case matches stuff in the table:

Wins.Changed:Connect(function()
   temporalData[plr.UserId].Wins = Wins.Value
end)
Coins.Changed:Connect(function()
   temporalData[plr.UserId].Coins = Coins.Value
end)
1 Like

I’ve edited it, is it good now?

1 Like

yes except you forgot another end) for playeradded connection

Alright, i delete the previous datastore, keep the leaderstats and add this table and it should work, right?

1 Like

Alright, will this work?

local temporalData = {}

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")
local ds2 = DataStore:GetDataStore("LeaderStatSave2")


game.Players.PlayerAdded:Connect(function(plr)
	local leader = Instance.new("Folder")
	leader.Name = "leaderstats"	
	local Cash = Instance.new("NumberValue",leader)

	Cash.Name = "Wins"

	local Cash2 = Instance.new("NumberValue",leader)
	Cash2.Name = "Coins"
	
	temporalData[plr.UserId] = ds:GetAsync(plr.UserId)
	--make all your bool values here
	local cash1 = temporalData[plr.UserId].Cash1
	if cash1 == nil then
		cash1 = false
	end
	Cash.Value = cash1
	Cash.Changed:connect(function()
		temporalData[plr.UserId].Cash1 = Cash.Value
	end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
	--Save it to one data store
	ds:SetAsync(plr.UserId, temporalData[plr.UserId])
	temporalData[plr.UserId] = nil
end)

And it broke, could you help please?

Add or {} when you get data

temporalData[plr.UserId] = ds:GetAsync(plr.UserId) or {}

This is my updated script

local temporalData = {}

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")
local ds2 = DataStore:GetDataStore("LeaderStatSave2")


game.Players.PlayerAdded:Connect(function(plr)
	local leader = Instance.new("Folder")
	leader.Name = "leaderstats"	
	local Cash = Instance.new("NumberValue",leader)

	Cash.Name = "Wins"

	local Cash2 = Instance.new("NumberValue",leader)
	Cash2.Name = "Coins"
	
	leader.Parent = plr
        temporalData[plr.UserId] = ds:GetAsync(plr.UserId) or {}
	--make all your bool values here
	local cash1 = temporalData[plr.UserId].Coins
	if cash1 == nil then
		cash1 = false
	end
	Cash.Value = cash1
	Cash.Changed:connect(function()
		temporalData[plr.UserId].Coins = Cash.Value
	end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
	--Save it to one data store
	ds:SetAsync(plr.UserId, temporalData[plr.UserId])
	temporal

Will it work?

Also parent leaderstats folder to plr and it should look like this
image

Still not working.

local temporalData = {}

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")
local ds2 = DataStore:GetDataStore("LeaderStatSave2")


game.Players.PlayerAdded:Connect(function(plr)
	local leader = Instance.new("Folder")
	leader.Name = "leaderstats"	
	local Cash = Instance.new("NumberValue",leader)

	Cash.Name = "Wins"

	local Cash2 = Instance.new("NumberValue",leader)
	Cash2.Name = "Coins"
	
	leader.Parent = plr
	temporalData[plr.UserId] = ds:GetAsync(plr.UserId)
	--make all your bool values here
	local cash1 = temporalData[plr.UserId].Coins
	if cash1 == nil then
		cash1 = 0
	end
	Cash.Value = cash1
	Cash.Changed:connect(function()
		temporalData[plr.UserId].Coins = Cash.Value
	end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
	--Save it to one data store
	ds:SetAsync(plr.UserId, temporalData[plr.UserId])
	temporalData[plr.UserId] = nil
end)

You’re setting cash1 to false if player had no previous data, change it to:

local cash1 = temporalData[plr.UserId].Coins or 0

Not working. Could you try on your roblox studio to see if it works for you, also yes the datastore setting is enabled, so it’s not that.

local temporalData = {}

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("LeaderStatSave")
local ds2 = DataStore:GetDataStore("LeaderStatSave2")


game.Players.PlayerAdded:Connect(function(plr)
	local leader = Instance.new("Folder")
	leader.Name = "leaderstats"	
	local Cash = Instance.new("NumberValue",leader)

	Cash.Name = "Wins"

	local Cash2 = Instance.new("NumberValue",leader)
	Cash2.Name = "Coins"

	leader.Parent = plr
	temporalData[plr.UserId] = ds:GetAsync(plr.UserId)
	--make all your bool values here
    local cash1 = temporalData[plr.UserId].Coins or 0
	Cash.Changed:connect(function()
		temporalData[plr.UserId].Coins = Cash.Value
	end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
	--Save it to one data store
	ds:SetAsync(plr.UserId, temporalData[plr.UserId])
	temporalData[plr.UserId] = nil
end)

You forgot to set Cash.Value to cash1 (and “or {}” disappeared)
and what exactly else is wrong about it?

Where do i put the “or {}”?
Also this “have you tried the heart button” is really annoying when im answering simple questions.