Hi! So I got a script to save my leaderstats but I don't have a default value set and I want the default value to be set for new players. Here is my script:
local ds = game:GetService("DataStoreService") local dss = ds:GetDataStore("CoolDataStore") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local stage = Instance.new("IntValue") stage.Name = "Stage" stage.Parent = leaderstats local data local success, errormessage = pcall(function() data = dss:GetAsync(player.UserId.."-stageNumber") end) if success then stage.Value = data print("kool aid somebody loaded data") end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() dss:SetAsync(player.UserId.."-stageNumber", player.leaderstats.Stage.Value) end) if success then print("Data Stored Successfully") else print(errormessage) end end)
Can somebody please help me on how to set a default value? i tried myself and it did not work .