Advertisement
Timon-Gun

16 часть Пост офис

Mar 29th, 2025
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.41 KB | None | 0 0
  1. -- Post Office | Local Script --
  2.  
  3. local replicatedstorage = game.ReplicatedStorage
  4. local USE_VIEWPORTS = game:GetService("ReplicatedStorage"):WaitForChild("UseViewports", math.huge)
  5.  
  6. local moduletowers = require(replicatedstorage:WaitForChild("Module_Towers"))
  7. local raritiesLayoutOrder = require(replicatedstorage:WaitForChild("Rarities LayoutOrder"))
  8. local gamefolder = replicatedstorage:WaitForChild("Game")
  9.  
  10. local InfoFrame = script.Parent.Parent:WaitForChild("Main"):WaitForChild("TowerInfo")
  11. local data = gamefolder:WaitForChild("Functions"):WaitForChild("GetInventoryData"):InvokeServer()
  12. local raritycolors = replicatedstorage:WaitForChild("RaritiesColors")
  13.  
  14. local abbreviator = require(replicatedstorage:WaitForChild("BigNumbersAbbreviator"))
  15. local cratesfolder = gamefolder:WaitForChild("CratesTowers")
  16. local userinput = game:GetService("UserInputService")
  17.  
  18.  
  19. local function SetAnimation(object, animName)
  20. local humanoid = object:WaitForChild("Humanoid")
  21. local animateFolder = object:WaitForChild("Animations")
  22.  
  23. if humanoid and animateFolder then
  24. local animationObject = animateFolder:WaitForChild(animName)
  25.  
  26. if animationObject then
  27. local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
  28.  
  29. local playingTracks = animator:GetPlayingAnimationTracks()
  30. for i, track in ipairs(playingTracks) do
  31. if track.Name == animName then
  32. return track
  33. end
  34. end
  35. --print(animator)
  36. local animationTrack = animator:LoadAnimation(animationObject)
  37. return animationTrack
  38. end
  39. end
  40. end
  41.  
  42. local function playAnimation(object, animName)
  43. local animationTrack = SetAnimation(object, animName)
  44.  
  45. if animationTrack then
  46. animationTrack:Play()
  47. else
  48. warn("Anim does not exist")
  49. return
  50. end
  51. end
  52.  
  53. local function viewportCreation(tower, modelParent, useAnim)
  54. if typeof(tower) == "Instance" and typeof(modelParent) == "Instance" then
  55. if modelParent:FindFirstChild("ViewportFrame") then
  56. if modelParent:FindFirstChild("ViewportFrame").WorldModel:FindFirstChildOfClass("Model") and modelParent.ViewportFrame.WorldModel:FindFirstChildOfClass("Model").Name ~= tower.Name or not modelParent.ViewportFrame.WorldModel:FindFirstChildOfClass("Model") then
  57. if modelParent.ViewportFrame.WorldModel:FindFirstChildOfClass("Model") then
  58. modelParent.ViewportFrame.WorldModel:FindFirstChildOfClass("Model"):Destroy()
  59. end
  60. if modelParent.ViewportFrame:FindFirstChild("Camera") then
  61. modelParent.ViewportFrame.Camera:Destroy()
  62. end
  63.  
  64. local newtowermodel = tower:Clone()
  65. newtowermodel.Parent = modelParent:WaitForChild("ViewportFrame"):WaitForChild("WorldModel")
  66.  
  67. local newcamera = Instance.new("Camera")
  68. newcamera.Parent = modelParent.ViewportFrame
  69. modelParent.ViewportFrame.CurrentCamera = newcamera
  70.  
  71. newcamera.CFrame = CFrame.new(newtowermodel.PrimaryPart.Position + newtowermodel.PrimaryPart.CFrame.LookVector * 1, newtowermodel.PrimaryPart.Position)
  72. newcamera.CFrame = newtowermodel.PrimaryPart.CFrame * CFrame.Angles(math.rad(0), math.rad(180),0) * CFrame.new(0,0,2)
  73. if useAnim then
  74. playAnimation(newtowermodel, "Test")
  75. end
  76. end
  77. end
  78. end
  79. end
  80.  
  81. local function MoveInfoUI(infoframetouse)
  82. local mouse = game:GetService("Players").LocalPlayer:GetMouse()
  83.  
  84. local positionoffset = 0
  85. local ScreenSize = workspace.CurrentCamera.ViewportSize
  86. --print(posXY.Y + (UISize.Y/2), ScreenSize.Y)
  87.  
  88. local posXY = UDim2.new(0.08, mouse.X, 0.2, mouse.Y)
  89. infoframetouse.Position = posXY
  90.  
  91. local UISize = infoframetouse.AbsoluteSize
  92. local UIAbsolutePosition = infoframetouse.AbsolutePosition
  93.  
  94. local uibottom = UIAbsolutePosition.Y + UISize.Y
  95.  
  96. if uibottom > (ScreenSize.Y) then
  97. local offset = uibottom - ScreenSize.Y
  98. positionoffset = offset
  99. else
  100. positionoffset = 0
  101. end
  102.  
  103. if positionoffset > 0 then
  104. infoframetouse.Position = posXY - UDim2.new(0, 0, 0.1, positionoffset)
  105. else
  106. infoframetouse.Position = posXY - UDim2.new(0, 0, 0, positionoffset)
  107. end
  108. end
  109.  
  110. local function LoadTowerInfo(tower, frametouse: Frame, tower2)
  111. if typeof(tower) == "table" and frametouse:IsA("Frame") then
  112. --frametouse.Visible = true
  113. for i,v in pairs(frametouse:GetChildren()) do
  114. if (tower[string.lower(v.Name)] or tower[v.Name]) and string.lower(v.Name) ~= "rarity" then
  115. local loweredName = string.lower(v.Name)
  116. if tower[loweredName] or tower[v.Name] and (tower["Max" .. loweredName] or tower["Max" .. v.Name]) then
  117. v:WaitForChild("Number").Text = (tower[loweredName] or tower[v.Name]) .. " -> " .. (tower["Max" .. loweredName] or tower["Max" .. v.Name])
  118. else
  119. v:WaitForChild("Number").Text = " ???"
  120. end
  121. elseif string.lower(v.Name) == "rarity" then
  122. local loweredName = string.lower(v.Name)
  123. if tower[loweredName] then
  124. if raritycolors:FindFirstChild(tower[loweredName]) then
  125. local Rarity_Color = raritycolors:FindFirstChild(tower[loweredName])
  126. Rarity_Color = Rarity_Color:Clone()
  127. v.TextColor3 = Color3.new(1,1,1)
  128. if v:FindFirstChildOfClass("UIGradient") then
  129. v:FindFirstChildOfClass("UIGradient"):Destroy()
  130. end
  131. Rarity_Color.Parent = v
  132. end
  133. v.Text = tower[loweredName]
  134. else
  135. v.Text = "???"
  136. end
  137. elseif string.lower(v.Name) == "nameholder" then
  138. local towerName = tower["name"]
  139. if towerName then
  140. v.Text = towerName
  141. else
  142. v.Text = "???"
  143. end
  144. elseif string.lower(v.Name) == "shiny" then
  145. local shinyidgot
  146. if typeof(tower2) == "table" and tower2["IDGot"] then
  147. shinyidgot = tower2["IDGot"]
  148. else
  149. shinyidgot = "???"
  150. end
  151. v.Text = "Shiny (#" .. shinyidgot .. ")"
  152. elseif string.lower(v.Name) == "sign" then
  153. local towersign
  154. if typeof(tower2) == "table" and tower2["Sign"] then
  155. towersign = tower2["Sign"]
  156. else
  157. towersign = "???"
  158. end
  159. v.Text = "Signed by: " .. towersign
  160. elseif string.lower(v.Name) == "gift" then
  161. local gifted
  162. if typeof(tower2) == "table" and tower2["Gift"] then
  163. gifted = tower2["Gift"]
  164. else
  165. gifted = "???"
  166. end
  167. v.Text = gifted.. " Gived You This Tower"
  168. end
  169. end
  170. if replicatedstorage:WaitForChild("Game"):WaitForChild("TowersExists"):FindFirstChild(tower2["name"]) then
  171. local existstower = replicatedstorage.Game.TowersExists:FindFirstChild(tower2["name"]).Value
  172.  
  173. local abbreviatedexists = abbreviator:Abbreviate(existstower, 1)
  174. frametouse:WaitForChild("TowersExistsNumber").Text = abbreviatedexists .. " Exists"
  175. else
  176. frametouse:WaitForChild("TowersExistsNumber").Text = "??? Exists"
  177. end
  178. end
  179. end
  180.  
  181. local function UpdateUnitsAfterGive()
  182. for _, child in pairs(script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits:GetChildren()) do
  183. if child:IsA("Frame") then
  184. child:Destroy()
  185. end
  186. end
  187. end
  188.  
  189. local function update()
  190. gamefolder:WaitForChild("Post"):WaitForChild("UpdateName"):FireServer(script.Parent.PostMenu.MainFrame.PlayerNameS.Text)
  191. end
  192.  
  193. local function RollImage()
  194. for i=1,4096 do
  195. script.Parent.PostMenu.MainFrame:WaitForChild("Process Frame"):WaitForChild("LoadingRing").Rotation += 2
  196. task.wait(0.0005)
  197. end
  198. end
  199. local function RollImage2()
  200. for i=1,4096 do
  201. script.Parent.PostMenu.Mails:WaitForChild("Process Frame"):WaitForChild("LoadingRing").Rotation += 2
  202. task.wait(0.0005)
  203. end
  204. end
  205. local function clearUnitsForUpdate()
  206. for i, v in pairs(script.Parent.PostMenu.MainFrame.YourUnits.YourUnits:GetChildren()) do
  207. if v:IsA("Frame") then
  208. v:Destroy()
  209. end
  210. end
  211. end
  212. local function UpdateMenu()
  213. if typeof(data) == "table" then
  214. task.wait(0.2)
  215. local temporaryRarities = {}
  216. for rarity,q in pairs(raritiesLayoutOrder) do
  217. temporaryRarities[rarity] = {}
  218. end
  219. for i, v in pairs(data["Towers"]) do
  220. local unitName = moduletowers[v["name"]]
  221. local units = script.YourUnit:Clone()
  222. for yayko, omg in pairs(script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits:GetChildren()) do
  223. script.GiveTowersVAL.Value = 0
  224. if omg:IsA("Frame") then
  225. omg:Destroy()
  226. end
  227. end
  228. units:WaitForChild("UnitPicture").Image = v["Image"]
  229. if v["Equipped"] or v["Starter"] then
  230. units:WaitForChild("UnitPicture"):WaitForChild("An_X").Visible = true
  231. end
  232. units:WaitForChild("UnitPicture").Activated:Connect(function()
  233. if units:WaitForChild("UnitPicture"):WaitForChild("IsInTrade").Visible then
  234. units.Parent = script.Parent.PostMenu.MainFrame.YourUnits.YourUnits
  235. script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible = false
  236. script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = true
  237. workspace:WaitForChild("Send"):WaitForChild("SurfaceGui"):WaitForChild("MainGUI"):WaitForChild("YourUnits").Visible = false
  238. workspace:WaitForChild("Send"):WaitForChild("SurfaceGui"):WaitForChild("MainGUI"):WaitForChild("YourUnits").Image = v["Image"]
  239. script.GiveTowersVAL.Value -= 1
  240. print(script.GiveTowersVAL.Value)
  241. if script.GiveTowersVAL.Value == 0 then
  242. script.GiveTowersVAL.Value = 0
  243. end
  244.  
  245. units:WaitForChild("UnitPicture"):WaitForChild("IsInTrade").Visible = false
  246. else
  247. if not v["Equipped"] and not v["Starter"] then
  248. units:WaitForChild("UnitPicture"):WaitForChild("An_X").Visible = false
  249. units:WaitForChild("UnitPicture"):WaitForChild("IsInTrade").Visible = true
  250. units.Parent = script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits
  251. script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible = true
  252. script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = false
  253. script.GiveTowersVAL.Value += 1
  254. print(script.GiveTowersVAL.Value)
  255. end
  256. end
  257. end)
  258. local towerinmoduler = moduletowers[v["name"]] or moduletowers[v["OldName"]]
  259.  
  260. if towerinmoduler then
  261. if v["Starter"] then
  262. units.LayoutOrder = 999999999
  263. else
  264. if raritiesLayoutOrder[towerinmoduler["rarity"]] then
  265. local antowerlayoutorder = raritiesLayoutOrder[towerinmoduler["rarity"]]
  266. if typeof(temporaryRarities[towerinmoduler["rarity"]]) ~= "table" then
  267. temporaryRarities[towerinmoduler["rarity"]] = {}
  268. end
  269. antowerlayoutorder = antowerlayoutorder - #temporaryRarities[towerinmoduler["rarity"]]
  270. units.LayoutOrder = antowerlayoutorder
  271. end
  272. end
  273.  
  274. local infoframetouse
  275. local tower = towerinmoduler
  276. if tower["Farm"] and tower["Farm"] == true then
  277. if v["Shiny"] and v["Shiny"] == true then
  278. if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
  279. infoframetouse = InfoFrame:WaitForChild("Farm Sign and Shiny")
  280. elseif (not v["Sign"]) or v["Sign"] == "" then
  281. infoframetouse = InfoFrame:WaitForChild("Farm Shiny")
  282. end
  283. elseif not v["Shiny"] then
  284. if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
  285. infoframetouse = InfoFrame:WaitForChild("Farm Sign")
  286. elseif (not v["Sign"]) or v["Sign"] == "" then
  287. infoframetouse = InfoFrame:WaitForChild("Farm")
  288. end
  289. end
  290. elseif not tower["Farm"] then -- If you want to add more towers types besides farms then either add them above, or add check here that its not that tower and then add it below
  291. if v["Shiny"] and v["Shiny"] == true then
  292. if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
  293. infoframetouse = InfoFrame:WaitForChild("Shiny and Sign")
  294. elseif (not v["Sign"]) or v["Sign"] == "" then
  295. infoframetouse = InfoFrame:WaitForChild("Shiny")
  296. end
  297. elseif not tower["Farm"] then -- If you want to add more towers types besides farms then either add them above, or add check here that its not that tower and then add it below
  298. if v["Gift"] and v["Gift"] == true then
  299. if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
  300. infoframetouse = InfoFrame:WaitForChild("Gift")
  301. elseif (not v["Sign"]) or v["Sign"] == "" then
  302. infoframetouse = InfoFrame:WaitForChild("Gift")
  303. end
  304. elseif not v["Shiny"] then
  305. if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
  306. infoframetouse = InfoFrame:WaitForChild("Sign")
  307. elseif (not v["Sign"]) or v["Sign"] == "" then
  308. infoframetouse = InfoFrame:WaitForChild("Normal")
  309. end
  310. end
  311. end
  312. end
  313. --print("Info frame to use 1:", infoframetouse)
  314. if not infoframetouse then
  315. infoframetouse = InfoFrame:WaitForChild("Normal")
  316. end
  317. --print("Info frame to use 2:", infoframetouse)
  318. units.MouseEnter:Connect(function()
  319. --print("Moved on to mouse fr")
  320. LoadTowerInfo(towerinmoduler, infoframetouse, v)
  321. MoveInfoUI(infoframetouse)
  322. infoframetouse.Visible = true
  323. end)
  324.  
  325. units.MouseMoved:Connect(function()
  326. --print("Moving mouse in")
  327. MoveInfoUI(infoframetouse)
  328. if not infoframetouse.Visible then
  329. infoframetouse.Visible = true
  330. end
  331. end)
  332. units.MouseLeave:Connect(function()
  333. --print("Mouse left")
  334. infoframetouse.Visible = false
  335. end)
  336. else
  337. warn("Couldn't find tower in module")
  338. end
  339. units.Parent = script.Parent.PostMenu.MainFrame.YourUnits.YourUnits
  340.  
  341. script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible = false
  342. script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = true
  343.  
  344. script.Parent.PostMenu.MainFrame.GiveTower.Activated:Connect(function()
  345. if units:FindFirstChild("UnitPicture") and units.UnitPicture.IsInTrade.Visible == true then
  346. if script.Parent.PostMenu.MainFrame.PlayerNameS.Text == game.Players.LocalPlayer.Name or script.Parent.PostMenu.MainFrame.PlayerNameS.Text == game.Players.LocalPlayer.DisplayName then
  347. print("Ne pishi svoy nik")
  348. else
  349. print("Yasno")
  350.  
  351.  
  352.  
  353. if script.Parent.PostMenu.MainFrame.PlayerNameS.Text == nil or script.Parent.PostMenu.MainFrame.PlayerNameS.Text == "" then
  354. print("Napishi Svoy Nik")
  355. else
  356. print("Ti Dal Igroky Unita pod nikom ",v["name"])
  357. script.GIVE.Value = true
  358. if script.GIVE.Value == true then
  359. print(v)
  360. script.Parent.PostMenu.MainFrame["Process Frame"].Visible = true
  361. gamefolder:WaitForChild("Post"):WaitForChild("GiveUnit"):FireServer(v["name"])
  362. task.spawn(RollImage)
  363. task.spawn(function()
  364. for Count, Roll in pairs(script.Parent.PostMenu.MainFrame:WaitForChild("ProcessFolder"):GetChildren()) do
  365. Roll.Visible = true
  366. script.Parent.PostMenu.MainFrame:WaitForChild("YourUnits").Visible = false
  367. script.Parent.PostMenu.MainFrame:WaitForChild("GiveTower").Visible = false
  368. script.Parent.PostMenu.MainFrame:WaitForChild("PlayerNameS").Visible = false
  369. end
  370. end)
  371. game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
  372. script.Parent.PostMenu.MainFrame.YourUnits.ProccessFrame.Visible = true
  373. script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible = false
  374. script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = false
  375. task.wait(13)
  376. script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = true
  377. script.Parent.PostMenu.MainFrame["Process Frame"].Visible = false
  378. task.spawn(function()
  379. for Count2, Roll2 in pairs(script.Parent.PostMenu.MainFrame:WaitForChild("ProcessFolder"):GetChildren()) do
  380. Roll2.Visible = false
  381. script.Parent.PostMenu.MainFrame:WaitForChild("YourUnits").Visible = true
  382. script.Parent.PostMenu.MainFrame:WaitForChild("GiveTower").Visible = true
  383. script.Parent.PostMenu.MainFrame:WaitForChild("PlayerNameS").Visible = true
  384. end
  385. end)
  386. script.GiveTowersVAL.Value -= 1
  387. print(v, " Gived")
  388. task.wait(1.5)
  389. task.spawn(UpdateMenu)
  390. task.spawn(clearUnitsForUpdate)
  391. game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
  392. end
  393. end
  394. end
  395. elseif not script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible and not script.GIVE.Value then
  396. print("Ne dam unitov")
  397. wait(1)
  398. script.GIVE.Value = false
  399. script.Parent.PostMenu.Got.Visible = false
  400. end
  401. end)
  402. end
  403. script.Parent.PostMenu.MainFrame.Mails.TextButton.Activated:Connect(function()
  404. script.Parent.PostMenu.MainFrame.Visible = false
  405. script.Parent.PostMenu.Mails.Visible = true
  406. end)
  407. script.Parent.PostMenu.Mails.PostOffice.TextButton.Activated:Connect(function()
  408. script.Parent.PostMenu.MainFrame.Visible = true
  409. script.Parent.PostMenu.Mails.Visible = false
  410. end)
  411. end
  412.  
  413. gamefolder:WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("CreateMail").OnClientEvent:Connect(function(playername, image)
  414. task.wait(0.5)
  415. for amount, MailTower in pairs(gamefolder:WaitForChild("Post"):WaitForChild("MailTowers"):GetChildren()) do
  416. if MailTower:IsA("StringValue") then
  417. task.wait(0.02)
  418. local CurrentMail = script.Mail:Clone()
  419. CurrentMail.Parent = script.Parent.PostMenu.Mails.ClaimOrDeclineUnit["Claim Or Decline"]
  420. CurrentMail.Name = MailTower.Value
  421. CurrentMail.UnitPIC.Image = image
  422. CurrentMail.TowerName.Text = MailTower.Value
  423. CurrentMail.PlrName.Text = "@".. playername
  424. task.wait(0.01)
  425. local MailToDel = gamefolder:WaitForChild("Post"):WaitForChild("MailTowers"):FindFirstChild(CurrentMail.Name).Value
  426.  
  427. CurrentMail.Claim.Activated:Connect(function()
  428. task.spawn(function()
  429. script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("Claim Or Decline").Visible = false
  430. script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("ProcessingFrame").Visible = true
  431. script.Parent.PostMenu.Mails:WaitForChild("Process Frame").Visible = true
  432. task.spawn(RollImage2)
  433. task.wait(13)
  434. script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("Claim Or Decline").Visible = true
  435. script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("ProcessingFrame").Visible = false
  436. script.Parent.PostMenu.Mails:WaitForChild("Process Frame").Visible = false
  437. end)
  438. CurrentMail:Destroy()
  439. gamefolder:WaitForChild("Post"):WaitForChild("MailTowers"):FindFirstChild(MailToDel):Destroy()
  440. gamefolder:WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("Claim"):FireServer(CurrentMail.Name, CurrentMail.Name)
  441. end)
  442. CurrentMail.Cancel.Activated:Connect(function()
  443. task.spawn(function()
  444. script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("Claim Or Decline").Visible = false
  445. script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("ProcessingFrame").Visible = true
  446. script.Parent.PostMenu.Mails:WaitForChild("Process Frame").Visible = true
  447. task.spawn(RollImage2)
  448. task.wait(13)
  449. script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("Claim Or Decline").Visible = true
  450. script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("ProcessingFrame").Visible = false
  451. script.Parent.PostMenu.Mails:WaitForChild("Process Frame").Visible = false
  452. end)
  453. CurrentMail:Destroy()
  454. gamefolder:WaitForChild("Post"):WaitForChild("MailTowers"):FindFirstChild(MailToDel):Destroy()
  455. gamefolder:WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("CancelClaim"):FireServer(CurrentMail.Name)
  456.  
  457. end)
  458. end
  459. end
  460. end)
  461. end
  462. task.spawn(function()
  463. while wait(1) do
  464. task.spawn(function()
  465. update(script.Parent.PostMenu.MainFrame.PlayerNameS.Text)
  466. end)
  467. task.spawn(function()
  468. data = gamefolder:WaitForChild("Functions"):WaitForChild("GetInventoryData"):InvokeServer()
  469. end)
  470. end
  471. end)
  472. script.Parent.Parent.PostOfficeFrame:GetPropertyChangedSignal("Visible"):Connect(function()
  473. if script.Parent.Parent.PostOfficeFrame.Visible == true then
  474. task.spawn(function()
  475. clearUnitsForUpdate()
  476. end)
  477. task.wait(0.2)
  478. task.spawn(function()
  479. UpdateMenu()
  480. end)
  481. end
  482. end)
  483.  
  484. -- PostOfficeHandler | Server Script --
  485.  
  486. local MemoryStore = game:GetService("MemoryStoreService")
  487. local Map = MemoryStore:GetSortedMap("SortedMap1")
  488. local PlayerDataHandler = require(game:GetService("ServerScriptService").Data)
  489.  
  490. local codegenerator = require(game:GetService("ServerStorage").UniqueCodeGenerator)
  491. local towers = require(game:GetService("ReplicatedStorage"):WaitForChild("Module_Towers"))
  492. local DataStoreService = game:GetService("DataStoreService")
  493.  
  494. local RepStorage = game:GetService("ReplicatedStorage")
  495. local PlayerName = game:GetService("ReplicatedStorage"):WaitForChild("Game"):WaitForChild("Post"):WaitForChild("PlrName")
  496. local function GiveTower(WhoSend, playerName, tower)
  497. task.wait(2)
  498. local playerKey = "NewData_" .. playerName
  499. local success, lastData = pcall(function()
  500. return Map:GetAsync(playerKey)
  501. end)
  502.  
  503. if success then
  504. task.wait(4)
  505. local currentData = lastData or {Towers = {}, LastLogout = os.time() }
  506. currentData["Towers"] = currentData["Towers"] or {}
  507. task.wait(0.01)
  508. tower["Sender"] = WhoSend
  509. task.wait(0.01)
  510. table.insert(currentData["Towers"], tower)
  511. task.wait(0.01)
  512. Map:SetAsync(playerKey, currentData, 604800)
  513. task.wait(0.01)
  514. print(currentData, currentData["Towers"], " Who Send Towers: ", WhoSend, tower)
  515. else
  516. end
  517. end
  518.  
  519. local function ReturnTowers(ReturnName, ReturnTower, TowerToGive)
  520. print("Function Activated")
  521. task.wait(2)
  522. print("OMG")
  523. local playerKey = "NewData_" .. ReturnName
  524. local success, lastData = pcall(function()
  525. return Map:GetAsync(playerKey)
  526. end)
  527. if success then
  528. task.wait(4)
  529. local currentData = lastData or {TowersToReturn = {}, LastLogout = os.time() }
  530. currentData["TowersToReturn"] = currentData["TowersToReturn"] or {}
  531. task.wait(0.01)
  532. table.insert(currentData["TowersToReturn"], TowerToGive)
  533. Map:SetAsync(playerKey, currentData, 604800)
  534. task.wait(0.01)
  535. print(currentData, currentData["TowersToReturn"], " Who Return Your Towers: ", ReturnTower["Sender"])
  536. else
  537. end
  538.  
  539. end
  540. local function ReceiveMail(player)
  541. local count = 0
  542. task.wait(4)
  543. local playerKey = "NewData_" .. player.Name
  544. local success, lastData = pcall(function()
  545. return Map:GetAsync(playerKey)
  546. end)
  547.  
  548. if success and lastData then
  549.  
  550. local data = PlayerDataHandler:ReturnProfile(player)
  551. if typeof(data) == "table" and data["Data"] then
  552. data = data["Data"]
  553. local towersToAdd = lastData["Towers"] or {}
  554. for _, tower in ipairs(towersToAdd) do
  555.  
  556. local updateMail = RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("ClaimedMail"):Clone()
  557. updateMail.Parent = RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("MailTowers")
  558. task.wait(0.1)
  559. for i, towers in pairs(game.ReplicatedStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("MailTowers"):GetChildren()) do
  560. print(i)
  561. task.wait(0.2)
  562. count = i
  563. end
  564. updateMail.Image.Value = tower["Image"]
  565. updateMail.Name = tower["name"]
  566. updateMail.Value = tower["name"]
  567. updateMail.Sender.Value = tower["Sender"]
  568. task.wait(0.025)
  569. print(updateMail, lastData["Towers"])
  570. print(count)
  571. if count == #lastData["Towers"] then
  572. print("OMG")
  573. RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("CreateMail"):FireClient(player, updateMail.Sender.Value, updateMail.Image.Value)
  574. end
  575. end
  576.  
  577. else
  578. end
  579. else
  580. end
  581. end
  582.  
  583. local function ReceiveReturnedTower(player)
  584. task.wait(4)
  585. local playerKey = "NewData_" .. player.Name
  586. local success, lastData = pcall(function()
  587. return Map:GetAsync(playerKey)
  588. end)
  589.  
  590. if success and lastData then
  591. local data = PlayerDataHandler:ReturnProfile(player)
  592. if typeof(data) == "table" and data["Data"] then
  593. data = data["Data"]
  594. local towersToAdd = lastData["TowersToReturn"] or {}
  595. local towersToRemove = {}
  596.  
  597. for _, tower in ipairs(towersToAdd) do
  598. for i = #lastData["TowersToReturn"], 1, -1 do
  599. local v = lastData["TowersToReturn"][i]
  600. if v["name"] == tower["name"] then
  601. v["UniqueID"] = tower["UniqueID"]
  602. end
  603. print(v["name"])
  604.  
  605. if v["UniqueID"] == tower["UniqueID"] then
  606. table.insert(data["Inventory"]["Towers"], tower)
  607. table.insert(towersToRemove, i)
  608. end
  609. end
  610. end
  611.  
  612. for i = #towersToRemove, 1, -1 do
  613. table.remove(lastData["TowersToReturn"], towersToRemove[i])
  614. end
  615.  
  616. task.wait(0.01)
  617. Map:SetAsync(playerKey, lastData, 604800)
  618. else
  619. print("No valid player data.")
  620. end
  621. else
  622. print("Error loading player data.")
  623. end
  624. end
  625.  
  626. game.Players.PlayerAdded:Connect(function(player)
  627. task.wait(2)
  628. local complete = RepStorage:WaitForChild("Game"):WaitForChild("Post"):FindFirstChild("Complete"):Clone()
  629. complete.Parent = player
  630. player:FindFirstChild("Complete").Value = player.Name
  631.  
  632. if player.Name == player:FindFirstChild("Complete").Value or player:FindFirstChild("Complete").Value == player.Name then
  633. task.spawn(function()
  634. ReceiveMail(player)
  635. end)
  636. task.spawn(function()
  637. ReceiveReturnedTower(player)
  638. end)
  639.  
  640. end
  641. end)
  642.  
  643. game.Players.PlayerRemoving:Connect(function(player)
  644. local playerKey = "NewData_" .. player.Name
  645. local success, lastdata = pcall(function()
  646. return Map:GetAsync(playerKey)
  647. end)
  648.  
  649. if success then
  650. if lastdata then
  651. print("Data loaded for", player.Name)
  652. lastdata["LastLogout"] = os.time()
  653. else
  654. print("No data found for", player.Name)
  655.  
  656. if lastdata then
  657. lastdata["LastLogout"] = os.time()
  658. end
  659. end
  660.  
  661. local success2, saveError = pcall(function()
  662. Map:SetAsync(playerKey, lastdata, 604800)
  663. end)
  664.  
  665. if success2 then
  666. print("Data saved successfully")
  667. else
  668. print("Error saving data:", saveError)
  669. end
  670. else
  671. print("Error loading data for", player.Name)
  672. end
  673. end)
  674.  
  675.  
  676. game.ReplicatedStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("GiveUnit").OnServerEvent:Connect(function(player, towername)
  677.  
  678. if player and player.Name ~= PlayerName.Value then
  679.  
  680. task.wait(1)
  681. local prldata = PlayerDataHandler:ReturnProfile(player)
  682. if typeof(prldata) == "table" and prldata["Data"] then
  683. print("LOADED")
  684. prldata = prldata["Data"]
  685. local TowerName = prldata["Inventory"]["Towers"]
  686.  
  687. for i, v in ipairs(TowerName) do
  688. if v["name"] ~= towername then
  689. continue
  690. end
  691. v["UniqueID"] = codegenerator:generateCode()
  692. print(towername, v, "Gived")
  693. table.remove(TowerName, i)
  694. GiveTower(player.Name, PlayerName.Value, v)
  695.  
  696. print("Tower in Mail")
  697.  
  698. break
  699. end
  700. end
  701. end
  702. end)
  703. RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("UpdateName").OnServerEvent:Connect(function(player, name)
  704. PlayerName.Value = name
  705. end)
  706.  
  707. RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("UpdateName").OnServerEvent:Connect(function(player, name)
  708. PlayerName.Value = name
  709. end)
  710. RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("Claim").OnServerEvent:Connect(function(player, TowerToDelete, TowerToGive)
  711. task.wait(4)
  712. local playerKey = "NewData_" .. player.Name
  713. local success, lastData = pcall(function()
  714. return Map:GetAsync(playerKey)
  715. end)
  716. if success and lastData then
  717. local data = PlayerDataHandler:ReturnProfile(player)
  718. if typeof(data) == "table" and data["Data"] then
  719. data = data["Data"]
  720. local removed = false
  721. local tower = table.clone(towers[TowerToGive])
  722. local updateMail = RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("ClaimedMail"):Clone()
  723. tower["UniqueID"] = codegenerator:generateCode()
  724. table.insert(data["Inventory"]["Towers"], tower)
  725. task.wait(0.05)
  726. for i = #lastData["Towers"], 1, -1 do
  727. local v = lastData["Towers"][i]
  728. v["UniqueID"] = tower["UniqueID"]
  729. task.wait(0.2)
  730. if v["UniqueID"] == tower["UniqueID"] and not removed then
  731. lastData["Towers"][i]["UniqueID"] = tower["UniqueID"]
  732. table.remove(lastData["Towers"], i)
  733. task.wait(0.1)
  734. removed = true
  735. end
  736. end
  737. Map:SetAsync(playerKey, lastData, 604800)
  738. end
  739. if #lastData["Towers"] == 0 then
  740. Map:SetAsync(playerKey, { Towers = {}, LastLogout = os.time() }, 604800)
  741. end
  742. end
  743. end)
  744.  
  745. RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("CancelClaim").OnServerEvent:Connect(function(player, TowerToReturn)
  746. task.wait(4)
  747. local playerKey = "NewData_" .. player.Name
  748. local success, lastData = pcall(function()
  749. return Map:GetAsync(playerKey)
  750. end)
  751. if success and lastData then
  752. local data = PlayerDataHandler:ReturnProfile(player)
  753. if typeof(data) == "table" and data["Data"] then
  754. data = data["Data"]
  755. local removed = false
  756. local tower = table.clone(towers[TowerToReturn])
  757. task.wait(0.01)
  758. tower["UniqueID"] = codegenerator:generateCode()
  759. task.spawn(function()
  760. for i = #lastData["Towers"], 1, -1 do
  761. local v = lastData["Towers"][i]
  762. print(v["Sender"])
  763. task.wait(0.05)
  764. ReturnTowers(v["Sender"], v, tower)
  765. break
  766. end
  767. end)
  768. task.wait(0.05)
  769. for i = #lastData["Towers"], 1, -1 do
  770. local v = lastData["Towers"][i]
  771. v["UniqueID"] = tower["UniqueID"]
  772. task.wait(0.2)
  773. if v["UniqueID"] == tower["UniqueID"] and not removed then
  774. lastData["Towers"][i]["UniqueID"] = tower["UniqueID"]
  775. table.remove(lastData["Towers"], i)
  776. task.wait(0.1)
  777. removed = true
  778. end
  779. end
  780. Map:SetAsync(playerKey, lastData, 604800)
  781. end
  782. if #lastData["Towers"] == 0 then
  783. Map:SetAsync(playerKey, { Towers = {}, LastLogout = os.time() }, 604800)
  784. end
  785. end
  786. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement