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

DataStore for level saving won't work?

Yes, I do have API access enabled.

local DSS = game:GetService("DataStoreService")
local leveldatastore = DSS:GetDataStore("LevelNumber")

game.Players.PlayerAdded:connect(function(player)
	local level = Instance.new("NumberValue",player)
	level.Name = "level"
	level.Value = leveldatastore:GetAsync(player.UserId) or 1
	leveldatastore:SetAsync(player.UserId,level.Value)
end)

1 answer

local DSS = game:GetService("DataStoreService")
local leveldatastore = DSS:GetDataStore("LevelNumber")
game.Players.PlayerAdded:connect(function(player)
	local PlayerStats = leveldatastore:GetAsync(game.Players[player.Name].UserId)
	if not PlayerStats then
		PlayerStats = 1
		leveldatastore:SetAsync(game.Players[player.Name].UserId, PlayerStats)
	end
	local level = Instance.new("IntValue")
	level.Name = "level"
	level.Value = PlayerStats
	level.Parent = game.Players[player.Name]
end)

2 comments

0

For future reference with datastores, I recormend https://scriptinghelpers.org/questions/25774

0

Please explain your code, where he went wrong, and what you did to fix it.

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