Randomized number save on leaderbord

I wanted to make it so that when a player enters the game for the first time it gives them a random number between 1 to 10 that loads the same number every time they rejoin which I’ll use later.

however I’m new to coding on roblox and everything I try ether doesn’t work or I didn’t understand in the first place so nothing shows up on the leaderboard

so far I have this as a script but I don’t know what I’m missing or what’s going wrong

local DataStoreService = game:GetService("DataStoreService")
local ClassStore = DataStoreService:GetDataStore("ClassStore")
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local UserId = Player.UserId
	local Class = ClassStore:GetAsync(UserId)
	
	if Class == nil then
		Class = math.random(1,10)
		ClassStore:SetAsync(UserId, Class)
	end
	
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "LeaderStats"
	
	local number = Instance.new("IntValue", Leaderstats)
	number.Name = "Number"
	number.Value = Class
	
end)

Okay so it’s been a really long time since I’ve done anything with leaderboards, but when I used them several years ago “leaderstats” needed to be all lowercase. Does that fix anything?

1 Like

Yes as he said, change it to “leaderstats”.
But also if u are trying this datasaving in studio, make sure u have enabled datastores usage from the published games settings.

just changing it to all lower didn’t work and its got studio access to api enabled

Well it should work just like that, so either u made a mistake or its just buggy

nvm I accidentally left one capital in, it works now