Advertisement
Sungmingamerpro13

My Story Game DataStore with Roles New (Main Game)

Apr 5th, 2024 (edited)
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 8.54 KB | None | 0 0
  1. local TeleportService = game:GetService("TeleportService")
  2. local SaveCurrency = game:GetService("DataStoreService"):GetDataStore("Rounds")
  3. local SaveCurrency2 = game:GetService("DataStoreService"):GetDataStore("Wins")
  4. local SaveCurrency3 = game:GetService("DataStoreService"):GetDataStore("Coins")
  5. local SaveExtraLives = game:GetService("DataStoreService"):GetDataStore("Lives")
  6. local SaveRoleData = game:GetService("DataStoreService"):GetDataStore("Role")
  7. local SaveMoneyData = game:GetService("DataStoreService"):GetDataStore("Money")
  8.  
  9. local VIPGamepassId = "265392817"
  10.  
  11. game.Players.PlayerAdded:Connect(function(player)
  12.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then
  13.         local Folder = Instance.new("Folder",player)
  14.         Folder.Name = "leaderstats"
  15.  
  16.         local Currency = Instance.new("NumberValue",Folder)
  17.         Currency.Name = game.ReplicatedStorage.Tags.RoundsValue.Value
  18.         Currency.Value = SaveCurrency:GetAsync(player.UserId) or 0
  19.  
  20.         local Currency2 = Instance.new("NumberValue",Folder)
  21.         Currency2.Name = game.ReplicatedStorage.Tags.WinsValue.Value
  22.         Currency2.Value = SaveCurrency2:GetAsync(player.UserId) or 0
  23.  
  24.         local previousData = SaveCurrency3:GetAsync(player.UserId)
  25.         local Coins
  26.  
  27.         if previousData ~= nil then
  28.             Coins = previousData
  29.         else
  30.             Coins = 0
  31.             SaveCurrency3:SetAsync(player.UserId, 0)
  32.         end
  33.  
  34.         local CoinsValue = Instance.new("NumberValue", player)
  35.         CoinsValue.Name = "Coins"
  36.         CoinsValue.Value = Coins
  37.  
  38.         local val1 = Instance.new("StringValue",player)
  39.         val1.Name = 'GotPet'
  40.         val1.Value = ''
  41.  
  42.         local val2 = Instance.new("StringValue",player)
  43.         val2.Name = 'OpenValue'
  44.         val2.Value = ''
  45.  
  46.         local previousData2 = SaveExtraLives:GetAsync(player.UserId)
  47.         local Lives
  48.        
  49.         local previousData3 = SaveRoleData:GetAsync(player.UserId)
  50.         local Role
  51.        
  52.         local previousData4 = SaveMoneyData:GetAsync(player.UserId)
  53.         local Money
  54.  
  55.         if previousData2 ~= nil then
  56.             Lives = previousData2
  57.         else
  58.             Lives = 0
  59.             SaveExtraLives:SetAsync(player.UserId, 0)
  60.         end
  61.        
  62.         if previousData3 ~= nil then
  63.             Role = previousData3
  64.         else
  65.             Role = player.Role.Value
  66.             SaveRoleData:SetAsync(player.UserId, player.Role.Value)
  67.         end
  68.        
  69.         if previousData4 ~= nil then
  70.             Money = previousData4
  71.         else
  72.             SaveMoneyData:SetAsync(player.UserId, 0)
  73.         end
  74.  
  75.         local ExtraLivesValue = Instance.new("NumberValue", player)
  76.         ExtraLivesValue.Name = "Lives"
  77.         ExtraLivesValue.Value = Lives
  78.        
  79.         local RoleValue = Instance.new("StringValue", player)
  80.         RoleValue.Name = "Role"
  81.         RoleValue.Value = Role
  82.        
  83.         if player:WaitForChild("Role").Value >= "Normal Kid" then
  84.             player.Character.Humanoid.MaxHealth = 100
  85.             player.Character.Humanoid.BodyDepthScale.Value = 0.7
  86.             player.Character.Humanoid.BodyHeightScale.Value = 0.7
  87.             player.Character.Humanoid.BodyWidthScale.Value = 0.6
  88.         elseif player:WaitForChild("Role").Value >= "Protector 1" then
  89.             player.Character.Humanoid.MaxHealth = 100
  90.             player.Character.Humanoid.BodyDepthScale.Value = 1
  91.             player.Character.Humanoid.BodyHeightScale.Value = 1
  92.             player.Character.Humanoid.BodyWidthScale.Value = 1
  93.         elseif player:WaitForChild("Role").Value >= "Medic" then
  94.             player.Character.Humanoid.MaxHealth = 100
  95.             player.Character.Humanoid.BodyDepthScale.Value = 1
  96.             player.Character.Humanoid.BodyHeightScale.Value = 1
  97.             player.Character.Humanoid.BodyWidthScale.Value = 1
  98.         elseif player:WaitForChild("Role").Value >= "Fighter" then
  99.             player.Character.Humanoid.MaxHealth = 100
  100.             player.Character.Humanoid.BodyDepthScale.Value = 0.7
  101.             player.Character.Humanoid.BodyHeightScale.Value = 0.7
  102.             player.Character.Humanoid.BodyWidthScale.Value = 0.6
  103.         elseif player:WaitForChild("Role").Value >= "Protector 3" then
  104.             player.Character.Humanoid.MaxHealth = 100
  105.             player.Character.Humanoid.BodyDepthScale.Value = 1
  106.             player.Character.Humanoid.BodyHeightScale.Value = 1
  107.             player.Character.Humanoid.BodyWidthScale.Value = 1
  108.         elseif player:WaitForChild("Role").Value >= "PREMIUM" then
  109.             player.Character.Humanoid.MaxHealth = 100
  110.             player.Character.Humanoid.BodyDepthScale.Value = 1
  111.             player.Character.Humanoid.BodyHeightScale.Value = 1
  112.             player.Character.Humanoid.BodyWidthScale.Value = 1
  113.         elseif player:WaitForChild("Role").Value >= "Default Kid" then
  114.             player.Character.Humanoid.MaxHealth = 100
  115.             player.Character.Humanoid.BodyDepthScale.Value = 1
  116.             player.Character.Humanoid.BodyHeightScale.Value = 1
  117.             player.Character.Humanoid.BodyWidthScale.Value = 1
  118.         elseif player:WaitForChild("Role").Value >= "Adventure" then
  119.             player.Character.Humanoid.MaxHealth = 100
  120.             player.Character.Humanoid.BodyDepthScale.Value = 1
  121.             player.Character.Humanoid.BodyHeightScale.Value = 1
  122.             player.Character.Humanoid.BodyWidthScale.Value = 1
  123.         elseif player:WaitForChild("Role").Value >= "Fat Kid" then
  124.             player.Character.Humanoid.MaxHealth = 100
  125.             player.Character.Humanoid.MaxHealth = 100
  126.             player.Character.Humanoid.BodyDepthScale.Value = 0.9
  127.             player.Character.Humanoid.BodyHeightScale.Value = 0.7
  128.             player.Character.Humanoid.BodyWidthScale.Value = 0.7
  129.         elseif player:WaitForChild("Role").Value >= "Golden Protector" then
  130.             player.Character.Humanoid.MaxHealth = 100
  131.             player.Character.Humanoid.BodyDepthScale.Value = 1
  132.             player.Character.Humanoid.BodyHeightScale.Value = 1
  133.             player.Character.Humanoid.BodyWidthScale.Value = 1
  134.         end
  135.        
  136.         local MoneyValue = Instance.new("NumberValue", player)
  137.         MoneyValue.Name = "Money"
  138.         MoneyValue.Value = Money
  139.  
  140.         if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, VIPGamepassId) then
  141.             player.Coins.Value = player.Coins.Value * 2
  142.         end
  143.     end
  144. end)
  145.  
  146. game.Players.PlayerRemoving:Connect(function(player)
  147.     if game.ReplicatedStorage.Tags.Leaderstats.Value == true then  
  148.         SaveCurrency:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.RoundsValue.Value].Value)
  149.         SaveCurrency2:SetAsync(player.UserId,player.leaderstats[game.ReplicatedStorage.Tags.WinsValue.Value].Value)
  150.     end
  151. end)
  152.  
  153. game:BindToClose(function()
  154.     print("STOPPED!")
  155.  
  156.     for i,player in pairs(game.Players:GetPlayers()) do
  157.         local value = player.Coins.Value
  158.         SaveCurrency3:SetAsync(player.UserId, value)
  159.         print("Saved data for "..player.Name)
  160.     end
  161. end)
  162.  
  163. game.Players.PlayerRemoving:Connect(function(player)
  164.     local value = player.Coins.Value
  165.  
  166.     if value ~= nil then
  167.         print("Found data to save for "..player.Name.."!")
  168.         SaveCurrency3:SetAsync(player.UserId, value)
  169.         print("Saved data for "..player.Name)
  170.     else
  171.         print("Did not manage to find data to save for "..player.Name.."!")
  172.     end
  173. end)
  174.  
  175. game:BindToClose(function()
  176.     print("STOPPED!")
  177.  
  178.     for i, player in pairs(game.Players:GetPlayers()) do
  179.         local value2 = player.Lives.Value
  180.         SaveExtraLives:SetAsync(player.UserId, value2)
  181.     end
  182. end)
  183.  
  184. game.Players.PlayerRemoving:Connect(function(player)
  185.     local value2 = player.Lives.Value
  186.  
  187.     if value2 ~= nil then
  188.         print("Found data to save for "..player.Name.."!")
  189.         SaveExtraLives:SetAsync(player.UserId, value2)
  190.         print("Saved data for "..player.Name)
  191.     else
  192.         print("Did not manage to find data to save for "..player.Name.."!")
  193.     end
  194. end)
  195.  
  196. game:BindToClose(function()
  197.     print("STOPPED!")
  198.  
  199.     for i, player in pairs(game.Players:GetPlayers()) do
  200.         local value3 = player.Role.Value
  201.         SaveRoleData:SetAsync(player.UserId, value3)
  202.     end
  203. end)
  204.  
  205. game.Players.PlayerRemoving:Connect(function(player)
  206.     local value3 = player.Role.Value
  207.  
  208.     if value3 ~= nil then
  209.         print("Found data to save for "..player.Name.."!")
  210.         SaveRoleData:SetAsync(player.UserId, value3)
  211.         print("Saved data for "..player.Name)
  212.     else
  213.         print("Did not manage to find data to save for "..player.Name.."!")
  214.     end
  215. end)
  216.  
  217. game:BindToClose(function()
  218.     print("STOPPED!")
  219.  
  220.     for i, player in pairs(game.Players:GetPlayers()) do
  221.         local value3 = player.Money.Value
  222.         SaveRoleData:SetAsync(player.UserId, value3)
  223.     end
  224. end)
  225.  
  226. game.Players.PlayerRemoving:Connect(function(player)
  227.     local value3 = player.Money.Value
  228.  
  229.     if value3 ~= nil then
  230.         print("Found data to save for "..player.Name.."!")
  231.         SaveRoleData:SetAsync(player.UserId, value3)
  232.         print("Saved data for "..player.Name)
  233.     else
  234.         print("Did not manage to find data to save for "..player.Name.."!")
  235.     end
  236. end)
  237.  
  238. game.Players.PlayerAdded:connect(function(player)
  239.     player.CharacterAdded:connect(function(char)
  240.  
  241.         char.Humanoid.Died:connect(function()
  242.             SaveCurrency:SetAsync(player.UserId, player.leaderstats.Rounds.Value)
  243.             SaveExtraLives:SetAsync(player.UserId, player.Lives.Value)
  244.             player.leaderstats.Rounds.Value = player.leaderstats.Rounds.Value + 1
  245.             player.Lives.Value = player.Lives.Value - 1
  246.         end)
  247.     end)
  248. end)
  249.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement