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

why is my game not auto saving the wins?

hi scripter, so, ive just made a auto save and leaderboard (on top of screen) But the save does not save... If you want to see it, here you go! https://www.roblox.com/games/722511272/Jumpy-racing-Under-construction But what am I doing wrong?

leaderboard

game.Players.PlayerAdded:connect(function(plr)
	local stats = Instance.new('IntValue', plr)
	stats.Name = 'leaderstats'
	local Points = Instance.new ('IntValue', stats)
	Points.Name = 'Wins'
end)

OrderedDataStore AutoSave

local DSService = game:GetService('DataStoreService'):GetDataStore('Hamburger223232')
game.Players.PlayerAdded:connect(function(plr)
	-- Define variables
	local uniquekey = 'id-'..plr.userId
	local leaderstats = Instance.new('IntValue', plr)
	local savevalue =  Instance.new('IntValue')
	leaderstats.Name = 'leaderstats'
	savevalue.Parent = leaderstats
	savevalue.Name = 'Wins'
	
	-- GetAsync
	local GetSaved = DSService:GetAsync(uniquekey)
	if GetSaved then
		savevalue.Value = GetSaved[1]
	else
		local NumbersForSaving = {savevalue.Value}
		DSService:SetAsync(uniquekey, NumbersForSaving)
	end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Wins.Value}
DSService:SetAsync(uniquekey, Savetable)	
	
	
end)

I hope you can help me out! thanks! good luck with other scripting!

-Gamer_io

1 comment

0

This is not an ordered data store this is a global data store.

1 answer

✓ Accepted answer

Paste this in a normal script inside of "ServerScriptService"

GetService = game:GetService("DataStoreService")
local Storage = GetService:GetDataStore("Hamburger223232")

game.Players.PlayerAdded:connect(function(Player)
	--LEADERSTATS--
	local User = Player.userId
	local UserKey = "User_"..User
	local SavedData = Storage:GetAsync(UserKey)
	local Stats = Instance.new("IntValue", Player)
	Stats.Name = "leaderstats"
	
	local Wins = Instance.new("IntValue", Stats)
	Wins.Name = "Wins"
	Wins.Value = 0
	
	--DataStore--
	if SavedData then
		Wins.Value = SavedData[1]
	else
		local NumbersNeeded = {Wins.Value}
		Storage:SetAsync(UserKey, NumbersNeeded)
	end
end)

game.Players.PlayerRemoving:connect(function(Player)
	local User = Player.userId
	local UserKey = "User_"..User
	local Savetable = {Player["leaderstats"].Wins.Value}
	Storage:SetAsync(UserKey, Savetable)
end)

Already Tested it and it works great!

2 comments

0

Be sure to check off the "Answered" box so I can get some points.

0

Thanks, it realy helped me!

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