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

Why is DataStore2 not working after I tested?(Please help)

Hi, I'm trying to learn how to use datastore 2, this is what I got and whenever I play and rejoin, it doesn't save. I can't test it on the studio as there is already a player in the Players section. So there wouldn't be any player added. Also, is it just me are is everyone having a new icon in the explorer name CorePackages that can't be deleted?

local DataStore2 = require(1936396537)
DataStore2.Combine("MasterKey", "Kills", "Deaths", "Coins")
game.Players.PlayerAdded:Connect(function(plr)
	local datakill = DataStore2("Kills", plr)
	local datadeath = DataStore2("Deaths", plr)
	local datacoin = DataStore2("Coins", plr)
	-- leaderboard
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = plr
	
	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = stats
	kills.Value = datakill:Get(0)
	
	local deaths = Instance.new("IntValue")
	deaths.Name = "Deaths"
	deaths.Parent = stats
	deaths.Value = datadeath:Get(0)
	
	local coin = Instance.new("IntValue")
	coin.Name = "Coins"
	coin.Parent = stats
	coin.Value = datacoin:Get(0)
	
	-- Save Kills
	datakill.Changed:Connect(function()
		datakill:Set(kills.Value)
	end)
	-- Save Deaths
	datadeath.Changed:Connect(function()
		datadeath:Set(deaths.Value)
	end)
	--Save Drachmas
	datacoin.Changed:Connect(function()
		datacoin:Set(coin.Value)
	end)


	-- On death event
	plr.CharacterAdded:Connect(function(char)
		local humanoid = char:FindFirstChild("Humanoid")
		humanoid.Died:Connect(function()
			deaths.Value = deaths.Value + 1
		end)
	end)
end)

Help please, Thank you!

5 comments

0

Shouldn't it save by players id? local datacoin = DataStore2("Coins", plr.UserId)?

0

Or you haven't turned on Allow HTTP Request?

0

hm, sure, let me try that

0

Urgh, the datastore script isn't even working on the studio, the leaderboard didn't even appeared

0

The script looks fine, problem is somewhere else. Maybe some rouge plugins?

1 answer

✓ Accepted answer

This doesnt work because you are using require by the ID please read the documentation for that

https://devforum.roblox.com/t/how-to-use-datastore2-data-store-caching-and-data-loss-prevention/136317

also you are increasing every value by a plus not the :Increment() Function here is a thread in the DevForums which shows a basic solution for your question

https://devforum.roblox.com/t/not-showing-leaderstats-when-using-datastore2/399573/17

1 comment

0

but didn't they said that we should use require to keep it up to date? But I did try the other option. Thanks

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