Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Post Office | Local Script --
- local replicatedstorage = game.ReplicatedStorage
- local USE_VIEWPORTS = game:GetService("ReplicatedStorage"):WaitForChild("UseViewports", math.huge)
- local moduletowers = require(replicatedstorage:WaitForChild("Module_Towers"))
- local raritiesLayoutOrder = require(replicatedstorage:WaitForChild("Rarities LayoutOrder"))
- local gamefolder = replicatedstorage:WaitForChild("Game")
- local InfoFrame = script.Parent.Parent:WaitForChild("Main"):WaitForChild("TowerInfo")
- local data = gamefolder:WaitForChild("Functions"):WaitForChild("GetInventoryData"):InvokeServer()
- local raritycolors = replicatedstorage:WaitForChild("RaritiesColors")
- local abbreviator = require(replicatedstorage:WaitForChild("BigNumbersAbbreviator"))
- local cratesfolder = gamefolder:WaitForChild("CratesTowers")
- local userinput = game:GetService("UserInputService")
- local function SetAnimation(object, animName)
- local humanoid = object:WaitForChild("Humanoid")
- local animateFolder = object:WaitForChild("Animations")
- if humanoid and animateFolder then
- local animationObject = animateFolder:WaitForChild(animName)
- if animationObject then
- local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
- local playingTracks = animator:GetPlayingAnimationTracks()
- for i, track in ipairs(playingTracks) do
- if track.Name == animName then
- return track
- end
- end
- --print(animator)
- local animationTrack = animator:LoadAnimation(animationObject)
- return animationTrack
- end
- end
- end
- local function playAnimation(object, animName)
- local animationTrack = SetAnimation(object, animName)
- if animationTrack then
- animationTrack:Play()
- else
- warn("Anim does not exist")
- return
- end
- end
- local function viewportCreation(tower, modelParent, useAnim)
- if typeof(tower) == "Instance" and typeof(modelParent) == "Instance" then
- if modelParent:FindFirstChild("ViewportFrame") then
- if modelParent:FindFirstChild("ViewportFrame").WorldModel:FindFirstChildOfClass("Model") and modelParent.ViewportFrame.WorldModel:FindFirstChildOfClass("Model").Name ~= tower.Name or not modelParent.ViewportFrame.WorldModel:FindFirstChildOfClass("Model") then
- if modelParent.ViewportFrame.WorldModel:FindFirstChildOfClass("Model") then
- modelParent.ViewportFrame.WorldModel:FindFirstChildOfClass("Model"):Destroy()
- end
- if modelParent.ViewportFrame:FindFirstChild("Camera") then
- modelParent.ViewportFrame.Camera:Destroy()
- end
- local newtowermodel = tower:Clone()
- newtowermodel.Parent = modelParent:WaitForChild("ViewportFrame"):WaitForChild("WorldModel")
- local newcamera = Instance.new("Camera")
- newcamera.Parent = modelParent.ViewportFrame
- modelParent.ViewportFrame.CurrentCamera = newcamera
- newcamera.CFrame = CFrame.new(newtowermodel.PrimaryPart.Position + newtowermodel.PrimaryPart.CFrame.LookVector * 1, newtowermodel.PrimaryPart.Position)
- newcamera.CFrame = newtowermodel.PrimaryPart.CFrame * CFrame.Angles(math.rad(0), math.rad(180),0) * CFrame.new(0,0,2)
- if useAnim then
- playAnimation(newtowermodel, "Test")
- end
- end
- end
- end
- end
- local function MoveInfoUI(infoframetouse)
- local mouse = game:GetService("Players").LocalPlayer:GetMouse()
- local positionoffset = 0
- local ScreenSize = workspace.CurrentCamera.ViewportSize
- --print(posXY.Y + (UISize.Y/2), ScreenSize.Y)
- local posXY = UDim2.new(0.08, mouse.X, 0.2, mouse.Y)
- infoframetouse.Position = posXY
- local UISize = infoframetouse.AbsoluteSize
- local UIAbsolutePosition = infoframetouse.AbsolutePosition
- local uibottom = UIAbsolutePosition.Y + UISize.Y
- if uibottom > (ScreenSize.Y) then
- local offset = uibottom - ScreenSize.Y
- positionoffset = offset
- else
- positionoffset = 0
- end
- if positionoffset > 0 then
- infoframetouse.Position = posXY - UDim2.new(0, 0, 0.1, positionoffset)
- else
- infoframetouse.Position = posXY - UDim2.new(0, 0, 0, positionoffset)
- end
- end
- local function LoadTowerInfo(tower, frametouse: Frame, tower2)
- if typeof(tower) == "table" and frametouse:IsA("Frame") then
- --frametouse.Visible = true
- for i,v in pairs(frametouse:GetChildren()) do
- if (tower[string.lower(v.Name)] or tower[v.Name]) and string.lower(v.Name) ~= "rarity" then
- local loweredName = string.lower(v.Name)
- if tower[loweredName] or tower[v.Name] and (tower["Max" .. loweredName] or tower["Max" .. v.Name]) then
- v:WaitForChild("Number").Text = (tower[loweredName] or tower[v.Name]) .. " -> " .. (tower["Max" .. loweredName] or tower["Max" .. v.Name])
- else
- v:WaitForChild("Number").Text = " ???"
- end
- elseif string.lower(v.Name) == "rarity" then
- local loweredName = string.lower(v.Name)
- if tower[loweredName] then
- if raritycolors:FindFirstChild(tower[loweredName]) then
- local Rarity_Color = raritycolors:FindFirstChild(tower[loweredName])
- Rarity_Color = Rarity_Color:Clone()
- v.TextColor3 = Color3.new(1,1,1)
- if v:FindFirstChildOfClass("UIGradient") then
- v:FindFirstChildOfClass("UIGradient"):Destroy()
- end
- Rarity_Color.Parent = v
- end
- v.Text = tower[loweredName]
- else
- v.Text = "???"
- end
- elseif string.lower(v.Name) == "nameholder" then
- local towerName = tower["name"]
- if towerName then
- v.Text = towerName
- else
- v.Text = "???"
- end
- elseif string.lower(v.Name) == "shiny" then
- local shinyidgot
- if typeof(tower2) == "table" and tower2["IDGot"] then
- shinyidgot = tower2["IDGot"]
- else
- shinyidgot = "???"
- end
- v.Text = "Shiny (#" .. shinyidgot .. ")"
- elseif string.lower(v.Name) == "sign" then
- local towersign
- if typeof(tower2) == "table" and tower2["Sign"] then
- towersign = tower2["Sign"]
- else
- towersign = "???"
- end
- v.Text = "Signed by: " .. towersign
- elseif string.lower(v.Name) == "gift" then
- local gifted
- if typeof(tower2) == "table" and tower2["Gift"] then
- gifted = tower2["Gift"]
- else
- gifted = "???"
- end
- v.Text = gifted.. " Gived You This Tower"
- end
- end
- if replicatedstorage:WaitForChild("Game"):WaitForChild("TowersExists"):FindFirstChild(tower2["name"]) then
- local existstower = replicatedstorage.Game.TowersExists:FindFirstChild(tower2["name"]).Value
- local abbreviatedexists = abbreviator:Abbreviate(existstower, 1)
- frametouse:WaitForChild("TowersExistsNumber").Text = abbreviatedexists .. " Exists"
- else
- frametouse:WaitForChild("TowersExistsNumber").Text = "??? Exists"
- end
- end
- end
- local function UpdateUnitsAfterGive()
- for _, child in pairs(script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits:GetChildren()) do
- if child:IsA("Frame") then
- child:Destroy()
- end
- end
- end
- local function update()
- gamefolder:WaitForChild("Post"):WaitForChild("UpdateName"):FireServer(script.Parent.PostMenu.MainFrame.PlayerNameS.Text)
- end
- local function RollImage()
- for i=1,4096 do
- script.Parent.PostMenu.MainFrame:WaitForChild("Process Frame"):WaitForChild("LoadingRing").Rotation += 2
- task.wait(0.0005)
- end
- end
- local function RollImage2()
- for i=1,4096 do
- script.Parent.PostMenu.Mails:WaitForChild("Process Frame"):WaitForChild("LoadingRing").Rotation += 2
- task.wait(0.0005)
- end
- end
- local function clearUnitsForUpdate()
- for i, v in pairs(script.Parent.PostMenu.MainFrame.YourUnits.YourUnits:GetChildren()) do
- if v:IsA("Frame") then
- v:Destroy()
- end
- end
- end
- local function UpdateMenu()
- if typeof(data) == "table" then
- task.wait(0.2)
- local temporaryRarities = {}
- for rarity,q in pairs(raritiesLayoutOrder) do
- temporaryRarities[rarity] = {}
- end
- for i, v in pairs(data["Towers"]) do
- local unitName = moduletowers[v["name"]]
- local units = script.YourUnit:Clone()
- for yayko, omg in pairs(script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits:GetChildren()) do
- script.GiveTowersVAL.Value = 0
- if omg:IsA("Frame") then
- omg:Destroy()
- end
- end
- units:WaitForChild("UnitPicture").Image = v["Image"]
- if v["Equipped"] or v["Starter"] then
- units:WaitForChild("UnitPicture"):WaitForChild("An_X").Visible = true
- end
- units:WaitForChild("UnitPicture").Activated:Connect(function()
- if units:WaitForChild("UnitPicture"):WaitForChild("IsInTrade").Visible then
- units.Parent = script.Parent.PostMenu.MainFrame.YourUnits.YourUnits
- script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible = false
- script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = true
- workspace:WaitForChild("Send"):WaitForChild("SurfaceGui"):WaitForChild("MainGUI"):WaitForChild("YourUnits").Visible = false
- workspace:WaitForChild("Send"):WaitForChild("SurfaceGui"):WaitForChild("MainGUI"):WaitForChild("YourUnits").Image = v["Image"]
- script.GiveTowersVAL.Value -= 1
- print(script.GiveTowersVAL.Value)
- if script.GiveTowersVAL.Value == 0 then
- script.GiveTowersVAL.Value = 0
- end
- units:WaitForChild("UnitPicture"):WaitForChild("IsInTrade").Visible = false
- else
- if not v["Equipped"] and not v["Starter"] then
- units:WaitForChild("UnitPicture"):WaitForChild("An_X").Visible = false
- units:WaitForChild("UnitPicture"):WaitForChild("IsInTrade").Visible = true
- units.Parent = script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits
- script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible = true
- script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = false
- script.GiveTowersVAL.Value += 1
- print(script.GiveTowersVAL.Value)
- end
- end
- end)
- local towerinmoduler = moduletowers[v["name"]] or moduletowers[v["OldName"]]
- if towerinmoduler then
- if v["Starter"] then
- units.LayoutOrder = 999999999
- else
- if raritiesLayoutOrder[towerinmoduler["rarity"]] then
- local antowerlayoutorder = raritiesLayoutOrder[towerinmoduler["rarity"]]
- if typeof(temporaryRarities[towerinmoduler["rarity"]]) ~= "table" then
- temporaryRarities[towerinmoduler["rarity"]] = {}
- end
- antowerlayoutorder = antowerlayoutorder - #temporaryRarities[towerinmoduler["rarity"]]
- units.LayoutOrder = antowerlayoutorder
- end
- end
- local infoframetouse
- local tower = towerinmoduler
- if tower["Farm"] and tower["Farm"] == true then
- if v["Shiny"] and v["Shiny"] == true then
- if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
- infoframetouse = InfoFrame:WaitForChild("Farm Sign and Shiny")
- elseif (not v["Sign"]) or v["Sign"] == "" then
- infoframetouse = InfoFrame:WaitForChild("Farm Shiny")
- end
- elseif not v["Shiny"] then
- if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
- infoframetouse = InfoFrame:WaitForChild("Farm Sign")
- elseif (not v["Sign"]) or v["Sign"] == "" then
- infoframetouse = InfoFrame:WaitForChild("Farm")
- end
- end
- 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
- if v["Shiny"] and v["Shiny"] == true then
- if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
- infoframetouse = InfoFrame:WaitForChild("Shiny and Sign")
- elseif (not v["Sign"]) or v["Sign"] == "" then
- infoframetouse = InfoFrame:WaitForChild("Shiny")
- end
- 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
- if v["Gift"] and v["Gift"] == true then
- if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
- infoframetouse = InfoFrame:WaitForChild("Gift")
- elseif (not v["Sign"]) or v["Sign"] == "" then
- infoframetouse = InfoFrame:WaitForChild("Gift")
- end
- elseif not v["Shiny"] then
- if v["Sign"] and typeof(v["Sign"]) == "string" and v["Sign"] ~= "" then
- infoframetouse = InfoFrame:WaitForChild("Sign")
- elseif (not v["Sign"]) or v["Sign"] == "" then
- infoframetouse = InfoFrame:WaitForChild("Normal")
- end
- end
- end
- end
- --print("Info frame to use 1:", infoframetouse)
- if not infoframetouse then
- infoframetouse = InfoFrame:WaitForChild("Normal")
- end
- --print("Info frame to use 2:", infoframetouse)
- units.MouseEnter:Connect(function()
- --print("Moved on to mouse fr")
- LoadTowerInfo(towerinmoduler, infoframetouse, v)
- MoveInfoUI(infoframetouse)
- infoframetouse.Visible = true
- end)
- units.MouseMoved:Connect(function()
- --print("Moving mouse in")
- MoveInfoUI(infoframetouse)
- if not infoframetouse.Visible then
- infoframetouse.Visible = true
- end
- end)
- units.MouseLeave:Connect(function()
- --print("Mouse left")
- infoframetouse.Visible = false
- end)
- else
- warn("Couldn't find tower in module")
- end
- units.Parent = script.Parent.PostMenu.MainFrame.YourUnits.YourUnits
- script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible = false
- script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = true
- script.Parent.PostMenu.MainFrame.GiveTower.Activated:Connect(function()
- if units:FindFirstChild("UnitPicture") and units.UnitPicture.IsInTrade.Visible == true then
- if script.Parent.PostMenu.MainFrame.PlayerNameS.Text == game.Players.LocalPlayer.Name or script.Parent.PostMenu.MainFrame.PlayerNameS.Text == game.Players.LocalPlayer.DisplayName then
- print("Ne pishi svoy nik")
- else
- print("Yasno")
- if script.Parent.PostMenu.MainFrame.PlayerNameS.Text == nil or script.Parent.PostMenu.MainFrame.PlayerNameS.Text == "" then
- print("Napishi Svoy Nik")
- else
- print("Ti Dal Igroky Unita pod nikom ",v["name"])
- script.GIVE.Value = true
- if script.GIVE.Value == true then
- print(v)
- script.Parent.PostMenu.MainFrame["Process Frame"].Visible = true
- gamefolder:WaitForChild("Post"):WaitForChild("GiveUnit"):FireServer(v["name"])
- task.spawn(RollImage)
- task.spawn(function()
- for Count, Roll in pairs(script.Parent.PostMenu.MainFrame:WaitForChild("ProcessFolder"):GetChildren()) do
- Roll.Visible = true
- script.Parent.PostMenu.MainFrame:WaitForChild("YourUnits").Visible = false
- script.Parent.PostMenu.MainFrame:WaitForChild("GiveTower").Visible = false
- script.Parent.PostMenu.MainFrame:WaitForChild("PlayerNameS").Visible = false
- end
- end)
- game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
- script.Parent.PostMenu.MainFrame.YourUnits.ProccessFrame.Visible = true
- script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible = false
- script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = false
- task.wait(13)
- script.Parent.PostMenu.MainFrame.YourUnits.YourUnits.Visible = true
- script.Parent.PostMenu.MainFrame["Process Frame"].Visible = false
- task.spawn(function()
- for Count2, Roll2 in pairs(script.Parent.PostMenu.MainFrame:WaitForChild("ProcessFolder"):GetChildren()) do
- Roll2.Visible = false
- script.Parent.PostMenu.MainFrame:WaitForChild("YourUnits").Visible = true
- script.Parent.PostMenu.MainFrame:WaitForChild("GiveTower").Visible = true
- script.Parent.PostMenu.MainFrame:WaitForChild("PlayerNameS").Visible = true
- end
- end)
- script.GiveTowersVAL.Value -= 1
- print(v, " Gived")
- task.wait(1.5)
- task.spawn(UpdateMenu)
- task.spawn(clearUnitsForUpdate)
- game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
- end
- end
- end
- elseif not script.Parent.PostMenu.MainFrame.YourUnits.ComplteChekingYourUnits.Visible and not script.GIVE.Value then
- print("Ne dam unitov")
- wait(1)
- script.GIVE.Value = false
- script.Parent.PostMenu.Got.Visible = false
- end
- end)
- end
- script.Parent.PostMenu.MainFrame.Mails.TextButton.Activated:Connect(function()
- script.Parent.PostMenu.MainFrame.Visible = false
- script.Parent.PostMenu.Mails.Visible = true
- end)
- script.Parent.PostMenu.Mails.PostOffice.TextButton.Activated:Connect(function()
- script.Parent.PostMenu.MainFrame.Visible = true
- script.Parent.PostMenu.Mails.Visible = false
- end)
- end
- gamefolder:WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("CreateMail").OnClientEvent:Connect(function(playername, image)
- task.wait(0.5)
- for amount, MailTower in pairs(gamefolder:WaitForChild("Post"):WaitForChild("MailTowers"):GetChildren()) do
- if MailTower:IsA("StringValue") then
- task.wait(0.02)
- local CurrentMail = script.Mail:Clone()
- CurrentMail.Parent = script.Parent.PostMenu.Mails.ClaimOrDeclineUnit["Claim Or Decline"]
- CurrentMail.Name = MailTower.Value
- CurrentMail.UnitPIC.Image = image
- CurrentMail.TowerName.Text = MailTower.Value
- CurrentMail.PlrName.Text = "@".. playername
- task.wait(0.01)
- local MailToDel = gamefolder:WaitForChild("Post"):WaitForChild("MailTowers"):FindFirstChild(CurrentMail.Name).Value
- CurrentMail.Claim.Activated:Connect(function()
- task.spawn(function()
- script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("Claim Or Decline").Visible = false
- script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("ProcessingFrame").Visible = true
- script.Parent.PostMenu.Mails:WaitForChild("Process Frame").Visible = true
- task.spawn(RollImage2)
- task.wait(13)
- script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("Claim Or Decline").Visible = true
- script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("ProcessingFrame").Visible = false
- script.Parent.PostMenu.Mails:WaitForChild("Process Frame").Visible = false
- end)
- CurrentMail:Destroy()
- gamefolder:WaitForChild("Post"):WaitForChild("MailTowers"):FindFirstChild(MailToDel):Destroy()
- gamefolder:WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("Claim"):FireServer(CurrentMail.Name, CurrentMail.Name)
- end)
- CurrentMail.Cancel.Activated:Connect(function()
- task.spawn(function()
- script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("Claim Or Decline").Visible = false
- script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("ProcessingFrame").Visible = true
- script.Parent.PostMenu.Mails:WaitForChild("Process Frame").Visible = true
- task.spawn(RollImage2)
- task.wait(13)
- script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("Claim Or Decline").Visible = true
- script.Parent.PostMenu.Mails:WaitForChild("ClaimOrDeclineUnit"):WaitForChild("ProcessingFrame").Visible = false
- script.Parent.PostMenu.Mails:WaitForChild("Process Frame").Visible = false
- end)
- CurrentMail:Destroy()
- gamefolder:WaitForChild("Post"):WaitForChild("MailTowers"):FindFirstChild(MailToDel):Destroy()
- gamefolder:WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("CancelClaim"):FireServer(CurrentMail.Name)
- end)
- end
- end
- end)
- end
- task.spawn(function()
- while wait(1) do
- task.spawn(function()
- update(script.Parent.PostMenu.MainFrame.PlayerNameS.Text)
- end)
- task.spawn(function()
- data = gamefolder:WaitForChild("Functions"):WaitForChild("GetInventoryData"):InvokeServer()
- end)
- end
- end)
- script.Parent.Parent.PostOfficeFrame:GetPropertyChangedSignal("Visible"):Connect(function()
- if script.Parent.Parent.PostOfficeFrame.Visible == true then
- task.spawn(function()
- clearUnitsForUpdate()
- end)
- task.wait(0.2)
- task.spawn(function()
- UpdateMenu()
- end)
- end
- end)
- -- PostOfficeHandler | Server Script --
- local MemoryStore = game:GetService("MemoryStoreService")
- local Map = MemoryStore:GetSortedMap("SortedMap1")
- local PlayerDataHandler = require(game:GetService("ServerScriptService").Data)
- local codegenerator = require(game:GetService("ServerStorage").UniqueCodeGenerator)
- local towers = require(game:GetService("ReplicatedStorage"):WaitForChild("Module_Towers"))
- local DataStoreService = game:GetService("DataStoreService")
- local RepStorage = game:GetService("ReplicatedStorage")
- local PlayerName = game:GetService("ReplicatedStorage"):WaitForChild("Game"):WaitForChild("Post"):WaitForChild("PlrName")
- local function GiveTower(WhoSend, playerName, tower)
- task.wait(2)
- local playerKey = "NewData_" .. playerName
- local success, lastData = pcall(function()
- return Map:GetAsync(playerKey)
- end)
- if success then
- task.wait(4)
- local currentData = lastData or {Towers = {}, LastLogout = os.time() }
- currentData["Towers"] = currentData["Towers"] or {}
- task.wait(0.01)
- tower["Sender"] = WhoSend
- task.wait(0.01)
- table.insert(currentData["Towers"], tower)
- task.wait(0.01)
- Map:SetAsync(playerKey, currentData, 604800)
- task.wait(0.01)
- print(currentData, currentData["Towers"], " Who Send Towers: ", WhoSend, tower)
- else
- end
- end
- local function ReturnTowers(ReturnName, ReturnTower, TowerToGive)
- print("Function Activated")
- task.wait(2)
- print("OMG")
- local playerKey = "NewData_" .. ReturnName
- local success, lastData = pcall(function()
- return Map:GetAsync(playerKey)
- end)
- if success then
- task.wait(4)
- local currentData = lastData or {TowersToReturn = {}, LastLogout = os.time() }
- currentData["TowersToReturn"] = currentData["TowersToReturn"] or {}
- task.wait(0.01)
- table.insert(currentData["TowersToReturn"], TowerToGive)
- Map:SetAsync(playerKey, currentData, 604800)
- task.wait(0.01)
- print(currentData, currentData["TowersToReturn"], " Who Return Your Towers: ", ReturnTower["Sender"])
- else
- end
- end
- local function ReceiveMail(player)
- local count = 0
- task.wait(4)
- local playerKey = "NewData_" .. player.Name
- local success, lastData = pcall(function()
- return Map:GetAsync(playerKey)
- end)
- if success and lastData then
- local data = PlayerDataHandler:ReturnProfile(player)
- if typeof(data) == "table" and data["Data"] then
- data = data["Data"]
- local towersToAdd = lastData["Towers"] or {}
- for _, tower in ipairs(towersToAdd) do
- local updateMail = RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("ClaimedMail"):Clone()
- updateMail.Parent = RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("MailTowers")
- task.wait(0.1)
- for i, towers in pairs(game.ReplicatedStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("MailTowers"):GetChildren()) do
- print(i)
- task.wait(0.2)
- count = i
- end
- updateMail.Image.Value = tower["Image"]
- updateMail.Name = tower["name"]
- updateMail.Value = tower["name"]
- updateMail.Sender.Value = tower["Sender"]
- task.wait(0.025)
- print(updateMail, lastData["Towers"])
- print(count)
- if count == #lastData["Towers"] then
- print("OMG")
- RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("CreateMail"):FireClient(player, updateMail.Sender.Value, updateMail.Image.Value)
- end
- end
- else
- end
- else
- end
- end
- local function ReceiveReturnedTower(player)
- task.wait(4)
- local playerKey = "NewData_" .. player.Name
- local success, lastData = pcall(function()
- return Map:GetAsync(playerKey)
- end)
- if success and lastData then
- local data = PlayerDataHandler:ReturnProfile(player)
- if typeof(data) == "table" and data["Data"] then
- data = data["Data"]
- local towersToAdd = lastData["TowersToReturn"] or {}
- local towersToRemove = {}
- for _, tower in ipairs(towersToAdd) do
- for i = #lastData["TowersToReturn"], 1, -1 do
- local v = lastData["TowersToReturn"][i]
- if v["name"] == tower["name"] then
- v["UniqueID"] = tower["UniqueID"]
- end
- print(v["name"])
- if v["UniqueID"] == tower["UniqueID"] then
- table.insert(data["Inventory"]["Towers"], tower)
- table.insert(towersToRemove, i)
- end
- end
- end
- for i = #towersToRemove, 1, -1 do
- table.remove(lastData["TowersToReturn"], towersToRemove[i])
- end
- task.wait(0.01)
- Map:SetAsync(playerKey, lastData, 604800)
- else
- print("No valid player data.")
- end
- else
- print("Error loading player data.")
- end
- end
- game.Players.PlayerAdded:Connect(function(player)
- task.wait(2)
- local complete = RepStorage:WaitForChild("Game"):WaitForChild("Post"):FindFirstChild("Complete"):Clone()
- complete.Parent = player
- player:FindFirstChild("Complete").Value = player.Name
- if player.Name == player:FindFirstChild("Complete").Value or player:FindFirstChild("Complete").Value == player.Name then
- task.spawn(function()
- ReceiveMail(player)
- end)
- task.spawn(function()
- ReceiveReturnedTower(player)
- end)
- end
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local playerKey = "NewData_" .. player.Name
- local success, lastdata = pcall(function()
- return Map:GetAsync(playerKey)
- end)
- if success then
- if lastdata then
- print("Data loaded for", player.Name)
- lastdata["LastLogout"] = os.time()
- else
- print("No data found for", player.Name)
- if lastdata then
- lastdata["LastLogout"] = os.time()
- end
- end
- local success2, saveError = pcall(function()
- Map:SetAsync(playerKey, lastdata, 604800)
- end)
- if success2 then
- print("Data saved successfully")
- else
- print("Error saving data:", saveError)
- end
- else
- print("Error loading data for", player.Name)
- end
- end)
- game.ReplicatedStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("GiveUnit").OnServerEvent:Connect(function(player, towername)
- if player and player.Name ~= PlayerName.Value then
- task.wait(1)
- local prldata = PlayerDataHandler:ReturnProfile(player)
- if typeof(prldata) == "table" and prldata["Data"] then
- print("LOADED")
- prldata = prldata["Data"]
- local TowerName = prldata["Inventory"]["Towers"]
- for i, v in ipairs(TowerName) do
- if v["name"] ~= towername then
- continue
- end
- v["UniqueID"] = codegenerator:generateCode()
- print(towername, v, "Gived")
- table.remove(TowerName, i)
- GiveTower(player.Name, PlayerName.Value, v)
- print("Tower in Mail")
- break
- end
- end
- end
- end)
- RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("UpdateName").OnServerEvent:Connect(function(player, name)
- PlayerName.Value = name
- end)
- RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("UpdateName").OnServerEvent:Connect(function(player, name)
- PlayerName.Value = name
- end)
- RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("Claim").OnServerEvent:Connect(function(player, TowerToDelete, TowerToGive)
- task.wait(4)
- local playerKey = "NewData_" .. player.Name
- local success, lastData = pcall(function()
- return Map:GetAsync(playerKey)
- end)
- if success and lastData then
- local data = PlayerDataHandler:ReturnProfile(player)
- if typeof(data) == "table" and data["Data"] then
- data = data["Data"]
- local removed = false
- local tower = table.clone(towers[TowerToGive])
- local updateMail = RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("ClaimedMail"):Clone()
- tower["UniqueID"] = codegenerator:generateCode()
- table.insert(data["Inventory"]["Towers"], tower)
- task.wait(0.05)
- for i = #lastData["Towers"], 1, -1 do
- local v = lastData["Towers"][i]
- v["UniqueID"] = tower["UniqueID"]
- task.wait(0.2)
- if v["UniqueID"] == tower["UniqueID"] and not removed then
- lastData["Towers"][i]["UniqueID"] = tower["UniqueID"]
- table.remove(lastData["Towers"], i)
- task.wait(0.1)
- removed = true
- end
- end
- Map:SetAsync(playerKey, lastData, 604800)
- end
- if #lastData["Towers"] == 0 then
- Map:SetAsync(playerKey, { Towers = {}, LastLogout = os.time() }, 604800)
- end
- end
- end)
- RepStorage:WaitForChild("Game"):WaitForChild("Post"):WaitForChild("Mail"):WaitForChild("CancelClaim").OnServerEvent:Connect(function(player, TowerToReturn)
- task.wait(4)
- local playerKey = "NewData_" .. player.Name
- local success, lastData = pcall(function()
- return Map:GetAsync(playerKey)
- end)
- if success and lastData then
- local data = PlayerDataHandler:ReturnProfile(player)
- if typeof(data) == "table" and data["Data"] then
- data = data["Data"]
- local removed = false
- local tower = table.clone(towers[TowerToReturn])
- task.wait(0.01)
- tower["UniqueID"] = codegenerator:generateCode()
- task.spawn(function()
- for i = #lastData["Towers"], 1, -1 do
- local v = lastData["Towers"][i]
- print(v["Sender"])
- task.wait(0.05)
- ReturnTowers(v["Sender"], v, tower)
- break
- end
- end)
- task.wait(0.05)
- for i = #lastData["Towers"], 1, -1 do
- local v = lastData["Towers"][i]
- v["UniqueID"] = tower["UniqueID"]
- task.wait(0.2)
- if v["UniqueID"] == tower["UniqueID"] and not removed then
- lastData["Towers"][i]["UniqueID"] = tower["UniqueID"]
- table.remove(lastData["Towers"], i)
- task.wait(0.1)
- removed = true
- end
- end
- Map:SetAsync(playerKey, lastData, 604800)
- end
- if #lastData["Towers"] == 0 then
- Map:SetAsync(playerKey, { Towers = {}, LastLogout = os.time() }, 604800)
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement