Advertisement
HowToRoblox

AchievementsGuiHandler

Dec 15th, 2022
1,155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.44 KB | None | 0 0
  1. local client:Player = game.Players.LocalPlayer
  2.  
  3. local clientAchievements:Folder = client:WaitForChild("ACHIEVEMENTS FOLDER")
  4.  
  5. local plrGui:PlayerGui = script.Parent
  6.  
  7. local mainGui:ScreenGui = plrGui:WaitForChild("AchievementsMainGui")
  8. local openMainButton:TextButton = mainGui:WaitForChild("OpenButton")
  9. local mainFrame:Frame = mainGui:WaitForChild("AchievementsFrame"); mainFrame.Visible = false
  10.  
  11. local notifGui:ScreenGui = plrGui:WaitForChild("AchievementsNotification"); notifGui.Enabled = false
  12. local notifFrame:Frame = notifGui:WaitForChild("NotificationFrame")
  13. local notifFramePos:UDim2 = notifFrame.Position
  14.  
  15.  
  16. local rs:ReplicatedStorage = game.ReplicatedStorage:WaitForChild("AchievementSystemReplicatedStorage")
  17. local remote:RemoteEvent = rs:WaitForChild("AchievementsRemoteEvent")
  18. local allAchievements:ModuleScript = require(rs:WaitForChild("AchievementsList"))
  19.  
  20.  
  21. --Open main GUI
  22. openMainButton.MouseButton1Click:Connect(function()
  23.     mainFrame.Visible = not mainFrame.Visible
  24. end)
  25.  
  26. --Close main GUI
  27. mainFrame:WaitForChild("CloseButton").MouseButton1Click:Connect(function()
  28.     mainFrame.Visible = false
  29. end)
  30.  
  31.  
  32. --Notification GUI
  33. local achievementsQueue = {}
  34.  
  35. remote.OnClientEvent:Connect(function(instruction, arg)
  36.    
  37.     if instruction == "AWARD ACHIEVEMENT" then
  38.        
  39.         local achievementInfo = allAchievements[arg]
  40.         if achievementInfo then
  41.             table.insert(achievementsQueue, arg)
  42.             repeat
  43.                 task.wait(0.2)
  44.             until table.find(achievementsQueue, arg) == 1
  45.            
  46.             local notifFrameClosedPos = notifFramePos + UDim2.new(notifFrame.Size.X.Scale, 0, 0, 0)
  47.            
  48.             notifFrame.Position = notifFrameClosedPos
  49.             notifFrame.AchievementName.Text = arg
  50.             notifFrame.AchievementImage.Image = type(achievementInfo.ImageId) == "number" and "rbxassetid://" .. achievementInfo.ImageId or achievementInfo.ImageId
  51.             notifFrame.Description.Text = achievementInfo.Description
  52.            
  53.             notifGui.Enabled = true
  54.            
  55.             notifFrame:TweenPosition(notifFramePos, "Out", "Quart", 0.8, true)
  56.            
  57.             task.wait(2)
  58.            
  59.             notifFrame:TweenPosition(notifFrameClosedPos, "In", "Quart", 0.8, true)
  60.            
  61.             task.wait(0.8)
  62.             notifGui.Enabled = false
  63.            
  64.             table.remove(achievementsQueue, table.find(achievementsQueue, arg))
  65.         end
  66.     end
  67. end)
  68.  
  69.  
  70. --Update main frame
  71. local function updateMain()
  72.     for _, frame in pairs(mainFrame:WaitForChild("AchievementsScroller"):GetChildren()) do
  73.         if frame:IsA("Frame") or frame:IsA("ImageLabel") or frame:IsA("ImageButton") or frame:IsA("TextButton") or frame:IsA("TextLabel") then
  74.             frame:Destroy()
  75.         end
  76.     end
  77.    
  78.     local newFrames = {}
  79.    
  80.     for achievement, achievementInfo in pairs(allAchievements) do
  81.         local name = achievement
  82.         local image = type(achievementInfo.ImageId) == "number" and "rbxassetid://" .. achievementInfo.ImageId or achievementInfo.ImageId
  83.         local desc = achievementInfo.Description
  84.         local owned = clientAchievements:FindFirstChild(name)
  85.        
  86.         local newFrame = script:WaitForChild("AchievementTemplate"):Clone()
  87.         newFrame.Name, newFrame.AchievementName.Text = name, name
  88.         newFrame.AchievementImage.Image = image
  89.         newFrame.Description.Text = desc
  90.         newFrame.Acquired.Visible = owned
  91.        
  92.         if not owned then
  93.             newFrame.ImageColor3 = Color3.fromRGB(newFrame.ImageColor3.R - 50, newFrame.ImageColor3.G - 50, newFrame.ImageColor3.B - 50)
  94.             for _, uiElement in pairs(newFrame:GetDescendants()) do
  95.                 if uiElement:IsA("Frame") then
  96.                     uiElement.BackgroundColor3 = Color3.fromRGB(uiElement.BackgroundColor3.R - 50, uiElement.BackgroundColor3.G - 50, uiElement.BackgroundColor3.B - 50)
  97.                 elseif uiElement:IsA("TextLabel") or uiElement:IsA("TextButton") then
  98.                     uiElement.BackgroundColor3 = Color3.fromRGB(uiElement.BackgroundColor3.R - 50, uiElement.BackgroundColor3.G - 50, uiElement.BackgroundColor3.B - 50)
  99.                     uiElement.TextColor3 = Color3.fromRGB(uiElement.TextColor3.R - 50, uiElement.TextColor3.G - 50, uiElement.TextColor3.B - 50)
  100.                 elseif uiElement:IsA("ImageLabel") or uiElement:IsA("ImageButton") then
  101.                     uiElement.ImageColor3 = Color3.fromRGB(uiElement.ImageColor3.R - 50, uiElement.ImageColor3.G - 50, uiElement.ImageColor3.B - 50)
  102.                 end
  103.             end
  104.         end
  105.        
  106.         table.insert(newFrames, newFrame)
  107.     end
  108.    
  109.     table.sort(newFrames, function(a, b)
  110.         return allAchievements[a.Name].OrderRank < allAchievements[b.Name].OrderRank
  111.     end)
  112.    
  113.     for _, newFrame in pairs(newFrames) do
  114.         newFrame.Parent = mainFrame.AchievementsScroller
  115.     end
  116. end
  117.  
  118. updateMain()
  119. clientAchievements.ChildAdded:Connect(updateMain)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement