Cakey3101

GAG Client 3

Aug 9th, 2025
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.29 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local Workspace = game:GetService("Workspace")
  3. local HttpService = game:GetService("HttpService")
  4. local TweenService = game:GetService("TweenService")
  5.  
  6. local Plots = Workspace:WaitForChild("Plots")
  7.  
  8. local Player = Players.LocalPlayer
  9.  
  10. local function AssignModelUUID(Model: Model)
  11.     local UUID = HttpService:GenerateGUID(false)
  12.     Model:SetAttribute("__UUID", UUID)
  13.    
  14.     for _, Part in ipairs(Model:GetDescendants()) do
  15.         if Part:IsA("BasePart") then
  16.             Part:SetAttribute("__TreeModelUUID", UUID)
  17.         end
  18.     end
  19. end
  20.  
  21. local function GetStepParts(Model: Model)
  22.     local Steps = {}
  23.    
  24.     for _, Part in ipairs(Model:GetDescendants()) do
  25.         if Part:IsA("BasePart") and tonumber(Part.Name) then
  26.             if Part:GetAttribute("__TreeModelUUID") == Model:GetAttribute("__UUID") then
  27.                 local Idx = tonumber(Part.Name)
  28.                 Steps[Idx] = Steps[Idx] or {}
  29.                 table.insert(Steps[Idx], Part)
  30.             end
  31.         end
  32.     end
  33.    
  34.     local Sorted = {}
  35.    
  36.     for Idx in pairs(Steps) do
  37.         table.insert(Sorted, Idx)
  38.     end
  39.    
  40.     table.sort(Sorted)
  41.    
  42.     return Steps, Sorted
  43. end
  44.  
  45. local function HideModelPart(Model: Model)
  46.     for _, Part in Model:GetDescendants() do
  47.         if Part:IsA("BasePart") then
  48.             Part.Transparency = 1
  49.            
  50.             for _, Text in ipairs(Part:GetDescendants()) do
  51.                 if Text:IsA("Texture") or Text:IsA("Decal") or Text:IsA("SurfaceAppearance") then
  52.                     if Text:GetAttribute("OriginalTransparency") == nil then
  53.                         Text:SetAttribute("OriginalTransparency", Text.Transparency)
  54.                     end
  55.                    
  56.                     Text.Transparency = 1
  57.                 end
  58.             end
  59.         end
  60.     end
  61. end
  62.  
  63. local function AnimateTreeGrowth(Model: Model)
  64.     task.spawn(function()
  65.         local PlantedAt = Model:GetAttribute("PlantedAt")
  66.         local GrowthTime = Model:GetAttribute("GrowthTime")
  67.         if not (PlantedAt and GrowthTime) then return end
  68.        
  69.         local Elapsed = Workspace:GetServerTimeNow() - PlantedAt
  70.         local Remaining = math.max(GrowthTime - Elapsed, 0)
  71.         local Steps, Sorted = GetStepParts(Model)
  72.         if #Sorted == 0 then return end
  73.        
  74.         local StepDuration = GrowthTime / #Sorted
  75.        
  76.         local function RestoreTextures(Part: BasePart)
  77.             for _, Text in ipairs(Part:GetDescendants()) do
  78.                 if Text:IsA("Texture") or Text:IsA("Decal") or Text:IsA("SurfaceAppearance") then
  79.                     local Orig = Text:GetAttribute("OriginalTransparency")
  80.                     if Orig ~= nil then
  81.                         Text.Transparency = Orig
  82.                     end
  83.                 end
  84.             end
  85.         end
  86.        
  87.         if Elapsed >= GrowthTime then
  88.             for _, Idx in ipairs(Sorted) do
  89.                 for _, Part in ipairs(Steps[Idx]) do
  90.                     local OrigSize = Part.Size
  91.                     local Rot = Part.CFrame - Part.Position
  92.                     local BaseY = OrigSize.Y / 2
  93.                     local Bottom = Part.Position - Vector3.new(0, BaseY, 0)
  94.                    
  95.                     Part.Size = OrigSize
  96.                     Part.CFrame = CFrame.new(Bottom + Vector3.new(0, BaseY, 0)) * Rot
  97.                     Part.Transparency = 0
  98.                     RestoreTextures(Part)
  99.                 end
  100.             end
  101.             -- Proximity Prompt
  102.             return
  103.         end
  104.        
  105.         -- Partial Growth
  106.         for i, Idx in ipairs(Sorted) do
  107.             local StartT = (i - 1) * StepDuration
  108.             local EndT = i * StepDuration
  109.            
  110.             for _, Part in ipairs(Steps[Idx]) do
  111.                 local OrigSize = Part.Size
  112.                 local Rot = Part.CFrame - Part.Position
  113.                 local BaseY = OrigSize.Y / 2
  114.                 local Bottom = Part.Position - Vector3.new(0, BaseY, 0)
  115.                 local StartSize = OrigSize / 5
  116.                 local HeightOffset = StartSize.Y / 2
  117.                
  118.                 if Elapsed >= EndT then
  119.                     Part.Size = OrigSize
  120.                     Part.CFrame = CFrame.new(Bottom + Vector3.new(0, BaseY, 0)) * Rot
  121.                     Part.Transparency = 0
  122.                     RestoreTextures(Part)
  123.                 elseif Elapsed >= StartT then
  124.                     local Prog = (Elapsed - StartT) / StepDuration
  125.                     local TargetSize = StartSize:Lerp(OrigSize, Prog)
  126.                     local TargetY = StartSize.Y / 2 + (BaseY - StartSize.Y / 2) * Prog
  127.                    
  128.                     Part.Size = TargetSize
  129.                     Part.CFrame = CFrame.new(Bottom + Vector3.new(0, TargetY, 0)) * Rot
  130.                     Part.Transparency = 0
  131.                     RestoreTextures(Part)
  132.                    
  133.                     TweenService:Create(Part,
  134.                         TweenInfo.new(StepDuration * (1 - Prog), Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
  135.                         {
  136.                             Size = OrigSize,
  137.                             CFrame = CFrame.new(Bottom + Vector3.new(0, BaseY, 0)) * Rot
  138.                         }
  139.                     ):Play()
  140.                 else
  141.                     Part.Size = StartSize
  142.                     Part.CFrame = CFrame.new(Bottom + Vector3.new(0, HeightOffset, 0)) * Rot
  143.                     Part.Transparency = 0
  144.                    
  145.                     for _, Text in ipairs(Part:GetDescendants()) do
  146.                         if Text:IsA("Texture") or Text:IsA("Decal") or Text:IsA("SurfaceAppearance") then
  147.                             Text.Transparency = 1
  148.                         end
  149.                     end
  150.                    
  151.                     local ThisPart = Part
  152.                    
  153.                     task.delay(StartT - Elapsed, function()
  154.                         ThisPart.Transparency = 0
  155.                         RestoreTextures(ThisPart)
  156.                         TweenService:Create(ThisPart,
  157.                             TweenInfo.new(StepDuration, Enum.EasingStyle.Quad, Enum.EasingDirection.Out),
  158.                             {
  159.                                 Size = OrigSize,
  160.                                 CFrame = CFrame.new(Bottom + Vector3.new(0, BaseY, 0)) * Rot
  161.                             }
  162.                         ):Play()
  163.                     end)
  164.                 end
  165.             end
  166.         end
  167.        
  168.         task.delay(Remaining, function()
  169.             -- Proximity Prompt
  170.         end)
  171.     end)
  172. end
  173.  
  174. local function StartAnimationForModel(Model: Model)
  175.     if Model:GetAttribute("__AnimateHooked") then return end
  176.     Model:SetAttribute("__AnimateHooked", true)
  177.    
  178.     local function RunAnim()
  179.         Model:SetAttribute("Animated", false)
  180.         HideModelPart(Model)
  181.         task.wait(0.5)
  182.         AssignModelUUID(Model)
  183.         AnimateTreeGrowth(Model)
  184.         Model:SetAttribute("Animated", true)
  185.     end
  186.    
  187.     RunAnim()
  188.    
  189.     Model:GetAttributeChangedSignal("PlantedAt"):Connect(RunAnim)
  190.     Model:GetAttributeChangedSignal("GrowthTime"):Connect(RunAnim)
  191. end
  192.  
  193. local function ConnectPlantedFolder(Planted: Folder)
  194.     for _, Model in Planted:GetChildren() do
  195.         StartAnimationForModel(Model)
  196.     end
  197.  
  198.     Planted.ChildAdded:Connect(function(Model: Model)
  199.         task.spawn(function()
  200.             for _ = 1, 50 do
  201.                 if Model:GetAttribute("PlantedAt") and Model:GetAttribute("GrowthTime") then
  202.                     break
  203.                 end
  204.                 task.wait(0.1)
  205.             end
  206.             StartAnimationForModel(Model)
  207.         end)
  208.     end)
  209. end
  210.  
  211. local function ConnectPlot(Plot: Model)
  212.     local P = Plot:FindFirstChild("Planted")
  213.    
  214.     if P then
  215.         ConnectPlantedFolder(P)
  216.     end
  217.    
  218.     Plot.ChildAdded:Connect(function(Child: Instance)
  219.         if Child:IsA("Folder") and Child.Name == "Planted" then
  220.             ConnectPlantedFolder(Child)
  221.         end
  222.     end)
  223. end
  224.  
  225. for _, Plot in ipairs(Plots:GetChildren()) do
  226.     ConnectPlot(Plot)
  227. end
  228.  
  229. Plots.ChildAdded:Connect(ConnectPlot)
Advertisement
Add Comment
Please, Sign In to add comment