Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TeleportService = game:GetService("TeleportService")
- local SaveRoles = game:GetService("DataStoreService"):GetDataStore("Role")
- game.Players.PlayerAdded:Connect(function(player)
- local PreviousData = SaveRoles:GetAsync(player.UserId)
- local Role
- if PreviousData ~= nil then
- Role = PreviousData
- else
- Role = script.Role.Value
- SaveRoles:SetAsync(player.UserId, Role)
- end
- local RoleValue = Instance.new("StringValue", player)
- RoleValue.Name = "Role"
- RoleValue.Value = Role
- player:WaitForChild("Role"):GetPropertyChangedSignal("Value"):Connect(function()
- player.Role.Value = player.Role.Value
- end)
- end)
- game:BindToClose(function()
- for i,player in pairs(game.Players:GetPlayers()) do
- local value = player.Role.Value
- SaveRoles:SetAsync(player.UserId, value)
- print("Saved data for "..player.Name)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local value = player.Role.Value
- if value ~= nil then
- print("Found data to save for "..player.Name.."!")
- SaveRoles:SetAsync(player.UserId, value)
- print("Saved data for "..player.Name)
- else
- print("Did not manage to find data to save for "..player.Name.."!")
- end
- end)
- local CashDataStore = game:GetService("DataStoreService"):GetDataStore("Cash")
- local GemsDataStore = game:GetService("DataStoreService"):GetDataStore("Gems")
- game.Players.PlayerAdded:Connect(function(player)
- local previousData = CashDataStore:GetAsync(player.UserId)
- local previousData2 = GemsDataStore:GetAsync(player.UserId)
- local Cash
- local Gems
- if previousData ~= nil then
- Cash = previousData
- else
- Cash = 0
- CashDataStore:SetAsync(player.UserId, Cash)
- end
- if previousData2 ~= nil then
- Gems = previousData2
- else
- Gems = 0
- GemsDataStore:SetAsync(player.UserId, Gems)
- end
- local CashValue = Instance.new("NumberValue", player)
- CashValue.Name = "Cash"
- CashValue.Value = Cash
- local gemsValue = Instance.new("NumberValue", player)
- gemsValue.Name = "Gems"
- gemsValue.Value = Gems
- end)
- game:BindToClose(function()
- for i,player in pairs(game.Players:GetPlayers()) do
- local value = player.Cash.Value
- local value2 = player.Gems.Value
- CashDataStore:SetAsync(player.UserId, value)
- GemsDataStore:SetAsync(player.UserId, value2)
- print("Saved data for "..player.Name)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local value = player.Cash.Value
- local value2 = player.Gems.Value
- if value ~= nil then
- print("Found data to save for "..player.Name.."!")
- CashDataStore:SetAsync(player.UserId, value)
- GemsDataStore:SetAsync(player.UserId, value2)
- print("Saved data for "..player.Name)
- else
- print("Did not manage to find data to save for "..player.Name.."!")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment