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)