Guest User

Untitled

a guest
Apr 14th, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. local DataStoreService = game:GetService("DataStoreService")
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local Players = game:GetService("Players")
  4.  
  5. local DataStore1 = DataStoreService:GetDataStore("DataStore1")
  6. local Update = ReplicatedStorage:WaitForChild("UpdateGui")
  7.  
  8. local function PlayerJoined(Joining)
  9.     local Leaderstats = Instance.new("Folder")
  10.     Leaderstats.Name = "leaderstats"
  11.     Leaderstats.Parent = Joining
  12.    
  13.     local Wins = Instance.new("IntValue")
  14.     Wins.Name = "Wins"
  15.     Wins.Value = 0
  16.     Wins.Parent = Leaderstats
  17.  
  18.     local DataPoiner = "Player_"..Joining.UserId
  19.     local Success, Response = pcall(DataStore1.GetAsync, DataStore1, DataPointer)
  20.  
  21.     if (Success) then
  22.         Wins.Value = tonumber(Response)
  23.     else
  24.         warn(Response)
  25.     end
  26.  
  27.     Update:FireAllClients(Wins.Value)
  28. end  
  29.  
  30. local function PlayerRemoved(Removing)
  31.     local Leaderstats = Removing:FindFirstChild("Leaderstats")
  32.     if (Leaderstats and Leaderstats.Wins) then
  33.         local DataPointer = "Player_"..Removing.UserId
  34.         local Success, Response = pcall(DataStore1.SetAsync, DataStore1, DataPointer, Wins.Value)
  35.         if (Success) then
  36.            print("Saved Wins ("..Wins.Value..") for "..Removing.Name)
  37.         else
  38.            warn(Response)
  39.         end
  40.     end
  41. end
  42.  
  43. Players.PlayerAdded:Connect(PlayerJoined)
  44. Players.PlayerRemoving:Connect(PlayerRemoved)
Advertisement
Add Comment
Please, Sign In to add comment