So i look at youtube how to do it but i look on the comments u can just use datastore, now im confused and i try this script
local dsservice = game:GetService("DataStoreService") local ds = dsservice:GetDataStore("PlayerData") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local crystal = Instance.new("IntValue") crystal.Name = "Crystal" crystal.Parent = leaderstats local level = Instance.new("IntValue") level.Name = "Level" level.Parent = leaderstats local win = Instance.new("IntValue") win.Name = "Win" win.Parent = leaderstats local id = "Player_" ..player.UserId local data local success, errorMessage = pcall(function() data = ds:GetAsync(id) end) if success then crystal.Value = data else warn(errorMessage) end end) game.Players.PlayerRemoving:Connect(function(player) local id = "Player_"..player.UserId local data = player.leaderstats.Crystal.Value local success, errorMessage = pcall(function() ds:SetAsync(id, data) end) end)
but still don't work (maybe because im using roblox studio not roblox player?) Can u guys help me?
If you want to load muliple data then you will have to use table like
local data = { player.leaderstats.ValueName.Value; player.leaderstats.ValueName.Value; }
Here is a related example to your script (you can just copy paste it):
local dsservice = game:GetService("DataStoreService") local ds = dsservice:GetDataStore("PlayerData") game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local crystal = Instance.new("IntValue") crystal.Name = "Crystal" crystal.Parent = leaderstats local level = Instance.new("IntValue") level.Name = "Level" level.Parent = leaderstats local win = Instance.new("IntValue") win.Name = "Win" win.Parent = leaderstats local id = "Player_" ..player.UserId local data local success, errorMessage = pcall(function() data = ds:GetAsync(id) end) if success then crystal.Value = data else warn(errorMessage) end end) game.Players.PlayerRemoving:Connect(function(player) local id = "Player_"..player.UserId local data = { player.leaderstats.Crystal.Value; player.leaderstats.Level.Value; player.leaderstats.Win.Value; } local success, errorMessage = pcall(function() ds:SetAsync(id, data) end) end)