Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DataStoreService = game:GetService("DataStoreService")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Players = game:GetService("Players")
- local DataStore1 = DataStoreService:GetDataStore("DataStore1")
- local Update = ReplicatedStorage:WaitForChild("UpdateGui")
- local function PlayerJoined(Joining)
- local Leaderstats = Instance.new("Folder")
- Leaderstats.Name = "leaderstats"
- Leaderstats.Parent = Joining
- local Wins = Instance.new("IntValue")
- Wins.Name = "Wins"
- Wins.Value = 0
- Wins.Parent = Leaderstats
- local DataPoiner = "Player_"..Joining.UserId
- local Success, Response = pcall(DataStore1.GetAsync, DataStore1, DataPointer)
- if (Success) then
- Wins.Value = tonumber(Response)
- else
- warn(Response)
- end
- Update:FireAllClients(Wins.Value)
- end
- local function PlayerRemoved(Removing)
- local Leaderstats = Removing:FindFirstChild("Leaderstats")
- if (Leaderstats and Leaderstats.Wins) then
- local DataPointer = "Player_"..Removing.UserId
- local Success, Response = pcall(DataStore1.SetAsync, DataStore1, DataPointer, Wins.Value)
- if (Success) then
- print("Saved Wins ("..Wins.Value..") for "..Removing.Name)
- else
- warn(Response)
- end
- end
- end
- Players.PlayerAdded:Connect(PlayerJoined)
- Players.PlayerRemoving:Connect(PlayerRemoved)
Advertisement
Add Comment
Please, Sign In to add comment