Advertisement
Timon-Gun

13 часть Баттл пасс

Nov 24th, 2024
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.08 KB | None | 0 0
  1. -- 1 скрипт в лобби локальный --
  2.  
  3.  
  4. wait(4)
  5.  
  6. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  7. local CurrencyRemote = ReplicatedStorage:WaitForChild("GiveCoinsRemote")
  8. local TowerRemote = ReplicatedStorage:WaitForChild("TowerRemote")
  9. local CrateRemote = ReplicatedStorage:WaitForChild("CratesRemote")
  10. local battlePassRemote = ReplicatedStorage:WaitForChild("BattlePassRemote")
  11.  
  12. local UserInputService = game:GetService("UserInputService")
  13. local currentTier = nil
  14.  
  15. local tiers = {
  16. {Name = "Tier 0", Reward = 0,Type = "Cash", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 0, TierValue = 0, Image = ""},
  17. {Name = "Tier 1", Reward = 100,Type = "Cash", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 0, TierValue = 1, Image = "rbxassetid://128156575674902"},
  18. {Name = "Tier 2", Reward = 200,Type = "Cash", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 20, TierValue = 2, Image = "rbxassetid://128156575674902"},
  19. {Name = "Tier 3", Reward = 300,Type = "Cash", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 40, TierValue = 3, Image = "rbxassetid://111033659398113"},
  20.  
  21. {Name = "Tier 4", Reward = 25,Type = "Gems", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 65, TierValue = 4, Image = "rbxassetid://101633758990575"},
  22. {Name = "Tier 5", Reward = 45,Type = "Gems", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 90, TierValue = 5, Image = "rbxassetid://101633758990575"},
  23. {Name = "Tier 6", Reward = "Mythic Tower 1", Type = "Tower", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 120, TierValue = 6, Image = "rbxassetid://80469276367256"},
  24.  
  25. {Name = "Tier 7", Reward = 250,Type = "Cash", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 150, TierValue = 7, Image = "rbxassetid://111033659398113"},
  26. {Name = "Tier 8", Reward = 450,Type = "Cash", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 180, TierValue = 8, Image = "rbxassetid://111033659398113"},
  27. {Name = "Tier 9", Reward = 50,Type = "Gems", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 200, TierValue = 9, Image = "rbxassetid://101633758990575"},
  28.  
  29. {Name = "Tier 10", Reward = 99,Type = "Gems", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 230, TierValue = 10, Image = "rbxassetid://101633758990575"},
  30. {Name = "Tier 11", Reward = 299,Type = "Cash", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 350, TierValue = 11, Image = "rbxassetid://111033659398113"},
  31. {Name = "Tier 12", Reward = "Example Crate", Type = "Crate", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 500, TierValue = 12, Image = "rbxassetid://133625418876443"},
  32. {Name = "Tier 13", Reward = "", Type = "", XP = ReplicatedStorage:WaitForChild("Game"):WaitForChild("XP").Value, Need = 0, TierValue = 0, Image = ""}
  33. }
  34.  
  35. local frame = script.Parent.Parent.ScrollingFrame
  36.  
  37. local completedTiers = {}
  38. local function updateUI()
  39.  
  40. for i, tier in ipairs(tiers) do
  41. local nexttier = tiers[i+1]
  42.  
  43. local tierLabel = frame:FindFirstChild(tier.Name) or Instance.new("Frame")
  44. local uistroke = Instance.new("UIStroke")
  45. local uicorner = Instance.new("UICorner")
  46. local imageframe = Instance.new("ImageLabel")
  47. uistroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
  48. uistroke.Thickness = 2
  49. uistroke.Parent = tierLabel
  50. uicorner.CornerRadius = UDim.new(0, 4.25)
  51. uicorner.Parent = tierLabel
  52. tierLabel.Name = tier.Name
  53. tierLabel.Size = UDim2.new(0, 125, 0, 125)
  54. tierLabel.Position = UDim2.new(0, 0, 0, (i - 1) * 60)
  55. tierLabel.BackgroundColor3 = Color3.new(0, 0.666667, 1)
  56.  
  57. imageframe.BackgroundTransparency = 1
  58. imageframe.Image = tier.Image
  59. imageframe.Size = UDim2.new(0, 80, 0, 80)
  60. imageframe.Position = UDim2.new(0.200, 0,0.000, 0)
  61. imageframe.Image = tier.Image
  62. imageframe.Parent = tierLabel
  63. tierLabel.Parent = frame
  64.  
  65. local claimButton = tierLabel:FindFirstChild("ClaimButton") or Instance.new("TextButton")
  66. local buttonuistroke = Instance.new("UIStroke")
  67. local textuistroke = Instance.new("UIStroke")
  68. local buttonuicorner = Instance.new("UICorner")
  69. textuistroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Contextual
  70. textuistroke.Thickness = 2.5
  71. textuistroke.Parent = claimButton
  72. buttonuicorner.CornerRadius = UDim.new(0, 4.25)
  73. buttonuicorner.Parent = claimButton
  74. claimButton.Name = "ClaimButton"
  75. claimButton.Text = "Claim"
  76. claimButton.BackgroundColor3 = Color3.new(0, 1, 0)
  77. claimButton.TextColor3 = Color3.new(1, 1, 1)
  78. claimButton.Font = Enum.Font.FredokaOne
  79. claimButton.TextScaled = true
  80.  
  81. claimButton.BackgroundTransparency = 0
  82. claimButton.Position = UDim2.new(0.001, 0,0.745, 0)
  83. claimButton.Size = UDim2.new(1.000, 0,0.256, 0)
  84. claimButton.Parent = tierLabel
  85. if table.find(completedTiers, tier.Name) then
  86. if not currentTier or tier.TierValue > currentTier.TierValue then
  87. currentTier = tier
  88. frame.Parent.Info.Tier.Text = currentTier.Name
  89. frame.Parent.ImageBox.ImageLabel.Image = currentTier.Image
  90. frame.Parent.Info.XP.Text = currentTier.XP .. " / " .. currentTier.Need
  91. frame.Parent.Info["Next Reward"].Text = "Next Reward :" .. nexttier.Reward .." Type : ".. nexttier.Type
  92. claimButton.Visible = false
  93. else
  94. claimButton.Visible = true
  95. end
  96. end
  97. if UserInputService.TouchEnabled then
  98. tierLabel.Size = UDim2.new(0, 75, 0, 75)
  99. tierLabel.Position = UDim2.new(0, 0, 0, (i - 1) * 90)
  100.  
  101. imageframe.Size = UDim2.new(0, 50, 0, 50)
  102. imageframe.Position = UDim2.new(0.185, 0,0.000, 0)
  103. end
  104.  
  105. claimButton.MouseButton1Click:Connect(function()
  106. local Type = tier.Type
  107. local reward = tier.Reward
  108.  
  109. if tier.XP >= tier.Need then
  110. if tier.Type == "Cash" or tier.Type == "Gems" then
  111. CurrencyRemote:FireServer(tier.Reward, Type)
  112. print(tier.Name, tier.Reward)
  113. game.ReplicatedStorage:WaitForChild("Game"):WaitForChild("Events"):WaitForChild("UpdateMoneyClient"):Fire()
  114. game.ReplicatedStorage:WaitForChild("Game"):WaitForChild("Events"):WaitForChild("UpdateMoneyClient"):Fire("Cash")
  115. game.ReplicatedStorage:WaitForChild("Game"):WaitForChild("Events"):WaitForChild("UpdateMoneyClient"):Fire("Gems")
  116. end
  117. if tier.Type == "Tower" then
  118. TowerRemote:FireServer(reward)
  119. print(tier.Name, tier.Reward)
  120. end
  121. if tier.Type == "Crate" then
  122. CrateRemote:FireServer(reward)
  123. print(tier.Name, tier.Reward)
  124. end
  125.  
  126. if not currentTier or tier.TierValue > currentTier.TierValue then
  127. currentTier = tier
  128. frame.Parent.Info.Tier.Text = currentTier.Name
  129. frame.Parent.ImageBox.ImageLabel.Image = currentTier.Image
  130. frame.Parent.Info["Next Reward"].Text = "Next Reward :" .. nexttier.Reward .." Type : ".. nexttier.Type
  131. frame.Parent.Info.XP.Text = currentTier.XP .. "/".. currentTier.Need
  132.  
  133. end
  134. table.insert(completedTiers, tier.Name)
  135. battlePassRemote:FireServer("SaveProgress", completedTiers)
  136. claimButton.Visible = false
  137. script.Parent.Parent.Got.Visible = true
  138. script.Parent.Parent.Got.Text = "✅ You Get " .. tier.Reward .. " " .. tier.Type .." In ".. tier.Name .. " ✅"
  139.  
  140. task.wait(2)
  141. script.Parent.Parent.Got.Visible = false
  142. else
  143. print("Not Enough Xp To Claim Tier")
  144. claimButton.Text = "Not Enough Xp"
  145. claimButton.BackgroundColor3 = Color3.new(0.262745, 0.262745, 0.262745)
  146. task.wait(2)
  147. claimButton.Text = "Claim"
  148. claimButton.BackgroundColor3 = Color3.new(0, 1, 0)
  149. end
  150. end)
  151. if tier.Name == "Tier 0" then
  152. tierLabel.Visible = false
  153. end
  154. if tier.Name == "Tier 13" then
  155. tierLabel.Visible = false
  156. end
  157. end
  158. end
  159.  
  160. local function loadProgress()
  161. battlePassRemote:FireServer("LoadProgress")
  162. end
  163.  
  164. battlePassRemote.OnClientEvent:Connect(function(completed)
  165. completedTiers = completed or {}
  166. updateUI()
  167. end)
  168.  
  169. loadProgress()
  170.  
  171. -- 2 скрипт серверный --
  172.  
  173. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  174. local battlePassRemote = ReplicatedStorage:WaitForChild("BattlePassRemote")
  175. local DataStoreService = game:GetService("DataStoreService")
  176. local PlayerDataStore = DataStoreService:GetDataStore("PlayerBattlePassProgress")
  177.  
  178.  
  179. local function loadProgress(player)
  180. local success, result = pcall(function()
  181. return PlayerDataStore:GetAsync(player.UserId)
  182. end)
  183.  
  184. if success and result then
  185. return result
  186. else
  187. return {}
  188. end
  189. end
  190.  
  191. local function saveProgress(player, completedTiers)
  192. local success, errorMessage = pcall(function()
  193. PlayerDataStore:SetAsync(player.UserId, completedTiers)
  194. end)
  195.  
  196. if not success then
  197. warn("Error when saving progress for player " .. player.Name .. ": " .. errorMessage)
  198. end
  199. end
  200.  
  201.  
  202. battlePassRemote.OnServerEvent:Connect(function(player, request, data)
  203. wait(1.5)
  204. if request == "LoadProgress" then
  205. local completedTiers = loadProgress(player)
  206. battlePassRemote:FireClient(player, completedTiers)
  207. elseif request == "SaveProgress" then
  208. saveProgress(player, data)
  209. end
  210. end)
  211.  
  212.  
  213. game.Players.PlayerAdded:Connect(function(player)
  214. local completedTiers = loadProgress(player)
  215. --battlePassRemote:FireClient(player, completedTiers)
  216. end)
  217.  
  218.  
  219. -- 3 скрипт серверный --
  220.  
  221. local PlayerData = require(game:GetService("ServerScriptService").Data)
  222. local towers = require(game:GetService("ReplicatedStorage"):WaitForChild("Module_Towers"))
  223. local cratesremote = game.ReplicatedStorage:WaitForChild("CratesRemote")
  224. local remote = game.ReplicatedStorage:WaitForChild("GiveCoinsRemote")
  225. local towersremote = game.ReplicatedStorage:WaitForChild("TowerRemote")
  226.  
  227. local codegenerator = require(game:GetService("ServerStorage").UniqueCodeGenerator)
  228.  
  229. local GameFolder = game:GetService("ReplicatedStorage"):WaitForChild("Game")
  230.  
  231. local FuncFolder = GameFolder:WaitForChild("Functions")
  232. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  233. local players = game.Players
  234. players.PlayerAdded:Connect(function(player)
  235. task.wait(2)
  236. local function ReceiveData(player)
  237. local data = PlayerData:ReturnProfile(player)
  238. if typeof(data) == "table" and data["Data"] then
  239. print("Found Existing Player Data.")
  240. data = data["Data"]
  241. return data
  242. else
  243. print("you can`t get a data")
  244. end
  245. end
  246.  
  247. remote.OnServerEvent:Connect(function(player, Amount, Type)
  248. local prldata = PlayerData:ReturnProfile(player)
  249. if typeof(prldata) == "table" and prldata["Data"] then
  250. prldata = prldata["Data"]
  251. print("ACTIVATED")
  252. prldata[Type] = prldata[Type] + Amount
  253. end
  254. end)
  255. towersremote.OnServerEvent:Connect(function(player, reward)
  256. local prldata = PlayerData:ReturnProfile(player)
  257. if typeof(prldata) == "table" and prldata["Data"] then
  258. prldata = prldata["Data"]
  259. local tower = table.clone(towers[reward])
  260. tower["UniqueID"] = codegenerator:generateCode()
  261. table.insert(prldata["Inventory"]["Towers"], tower)
  262. print("ACTIVATED")
  263. end
  264. end)
  265. cratesremote.OnServerEvent:Connect(function(player, reward)
  266. local prldata = PlayerData:ReturnProfile(player)
  267. if typeof(prldata) == "table" and prldata["Data"] then
  268. prldata = prldata["Data"]
  269. local cratetogive = {
  270.  
  271. ["CrateName"] = reward,
  272.  
  273. ["UniqueID"] = codegenerator:generateCode()
  274.  
  275. }
  276. table.insert(prldata["Inventory"]["Crates"], cratetogive)
  277. print("ACTIVATED")
  278. end
  279. end)
  280.  
  281. GameFolder:WaitForChild("Events"):WaitForChild("UpdateClientMoney").OnServerEvent:Connect(function(currency)
  282. PlayerData["Cash"] = FuncFolder:WaitForChild("GetCurrency"):InvokeClient(currency)
  283. PlayerData["Gems"] = FuncFolder:WaitForChild("GetCurrency"):InvokeClient(currency)
  284. end)
  285. while wait(0.25) do
  286. GameFolder:WaitForChild("Events"):WaitForChild("UpdateMoneyClient"):Fire()
  287. GameFolder:WaitForChild("Events"):WaitForChild("UpdateMoneyClient"):Fire("Cash")
  288. GameFolder:WaitForChild("Events"):WaitForChild("UpdateMoneyClient"):Fire("Gems")
  289. end
  290.  
  291. game:GetService("ReplicatedStorage").Game.Functions.GetCurrency.OnServerInvoke = ReceiveData
  292.  
  293. end)
  294.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement