Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Heres an example for saving and loading data
- local dss=game:GetService("DataStoreService"):GetDataStore("Lol")
- function onJoined(player)
- local key="user_"..player.UserId
- local credits=Instance.new("StringValue", player)
- credits.Name="Credits"
- credits.Value=dss:GetAsync(key) or 0
- end
- function onLeft(player)
- local key="user_"..player.UserId
- local success, message=pcall(function()
- dss:SetAsync(key, player.Credits.Value)
- end)
- if success then
- print("Saved " .. player.Name .. " data")
- else
- print("Failed to save " ..player.Name .. " data." ..message)
- end
- end
- game.Players.ChildAdded:Connect(function(player) onJoined(player) end)
- game.Players.ChildRemoved:Connect(function(player) onLeft(player) end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement