Advertisement
Guest User

Untitled

a guest
May 17th, 2025
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. function PlantHandler.InitializePlant(player, plantFolder, config, plantCircle)
  2. local circlePos = plantCircle.Position
  3. local plantCF = CFrame.new(circlePos) * CFrame.Angles(0, math.rad(math.random(-180, 180)), 0)
  4. local plantScale = math.random(config.MinScale * 100, config.MaxScale * 100)/100
  5.  
  6. local mass = config.DefaultMass * plantScale
  7.  
  8. mass = math.round(mass * 100)/100
  9.  
  10. local plot = plotHandler.GetPlot(player)
  11.  
  12. local mutation = determineMutation(plantFolder)
  13.  
  14. if plantFolder:FindFirstChild(mutation) then
  15. plantFolder = plantFolder:FindFirstChild(mutation)
  16. else
  17. return nil
  18. end
  19.  
  20. local plantStages = plantFolder:GetChildren()
  21.  
  22. table.sort(plantStages, function(a, b)
  23. local aValue = a:FindFirstChild("Stage").Value
  24. local bValue = b:FindFirstChild("Stage").Value
  25.  
  26. return aValue < bValue
  27. end)
  28.  
  29. local timePerStage = config.GrowTime/(#plantStages + 1)
  30.  
  31. local isFullGrown = false
  32. local currentStage = 0
  33.  
  34. local plant = nil
  35.  
  36. local finalStage = plantStages[#plantStages]:Clone()
  37. finalStage.Name = config.DisplayName
  38. finalStage.Parent = plot.Plants
  39. finalStage:PivotTo(plantCF)
  40.  
  41. scaleModel(finalStage, plantScale)
  42.  
  43. local finalStageParts = {}
  44.  
  45. for _, part in pairs(finalStage:GetDescendants()) do
  46. if part:IsA("Part") then
  47. local defaultTr = part.Transparency
  48. local defaultCanCollide = part.CanCollide
  49.  
  50. finalStageParts[part] = {}
  51. finalStageParts[part].Transparency = defaultTr
  52. finalStageParts[part].CanCollide = defaultCanCollide
  53.  
  54. part.CanQuery = false
  55. part.Transparency = 1
  56. part.CanCollide = false
  57. end
  58. end
  59.  
  60. if not PlantHandler.Plants[player] then
  61. PlantHandler.Plants[player] = {}
  62. end
  63.  
  64. PlantHandler.Plants[player][finalStage] = {}
  65. PlantHandler.Plants[player][finalStage].GrowStartTime = os.time()
  66.  
  67. task.spawn(function()
  68. while not isFullGrown do
  69. task.wait(timePerStage)
  70.  
  71. if currentStage < #plantStages then
  72. currentStage += 1
  73.  
  74. if plantCircle then
  75. plantCircle:Destroy()
  76. end
  77. if plant then
  78. plant:Destroy()
  79. end
  80.  
  81. if currentStage == #plantStages then
  82. isFullGrown = true
  83.  
  84. for _, part in pairs(finalStage:GetDescendants()) do
  85. if part:IsA("Part") then
  86. part.CanQuery = true
  87.  
  88. if finalStageParts[part] then
  89. part.Transparency = finalStageParts[part].Transparency
  90. part.CanCollide = finalStageParts[part].CanCollide
  91. end
  92. end
  93. end
  94. else
  95. plant = plantStages[currentStage]:Clone()
  96. plant.Parent = plot:FindFirstChild("Plants")
  97. plant:PivotTo(plantCF * CFrame.new(0, plant.PrimaryPart.Size.Y/2, 0))
  98.  
  99. scaleModel(plant, plantScale)
  100. end
  101. end
  102. end
  103.  
  104. local harvestPrompt = templates.HarvestPrompt:Clone()
  105. harvestPrompt.Parent = finalStage
  106. harvestPrompt.Name = config.DisplayName
  107.  
  108. local connection
  109.  
  110. connection = harvestPrompt.Triggered:Connect(function(playerWhoTriggered)
  111. if playerWhoTriggered == player then
  112. harvestPlant(player, finalStage, mass)
  113.  
  114. harvestPrompt:Destroy()
  115.  
  116. connection:Disconnect()
  117. end
  118. end)
  119. end)
  120. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement