Advertisement
drakon-firestone

Drops

May 10th, 2023
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local TweenService = game:GetService("TweenService")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local RunService = game:GetService("RunService")
  5. local player = Players.LocalPlayer
  6.  
  7. local remotes = ReplicatedStorage:WaitForChild("Remotes")
  8. local despawnedDrops = ReplicatedStorage:WaitForChild("DespawnedDrops")
  9.  
  10. local playersFolder = workspace.Players
  11. local drops = workspace.Drops
  12.  
  13.  
  14.  
  15. for _, drop in pairs(drops:GetDescendants()) do
  16.  
  17. if drop:IsA("Model") then
  18.  
  19. drop.CurrentPoints.Value = drop.MaxPoints.Value
  20.  
  21. drop.ClickDetector.MouseClick:Connect(function(player)
  22.  
  23. local currentPlayerPets = playersFolder[player.Name]:GetChildren()
  24. if #currentPlayerPets > 0 then
  25.  
  26. if player.Areas:FindFirstChild(drop.Parent.Name) then
  27.  
  28. for _, pet in pairs(currentPlayerPets) do
  29.  
  30. if pet.Attack.Value == drop.PrimaryPart then
  31. -- pet atakuje juz klikniety drop - wtedy ma przestać
  32. pet.Attack.Value = nil
  33. else
  34. -- pet nie atakuje kliknietego dropu - wtedy ma go zaatakować
  35. pet.Attack.Value = drop.PrimaryPart
  36. end
  37.  
  38. end
  39.  
  40. end
  41.  
  42. end
  43. end)
  44.  
  45. end
  46. end
  47.  
  48. local function destroyDrop(drop)
  49. task.spawn(function()
  50.  
  51. local oldParent = drop.Parent
  52. drop.Parent = despawnedDrops
  53. wait(4)
  54. drop.CurrentPoints.Value = drop.MaxPoints.Value
  55. drop.Parent = oldParent
  56. end)
  57. end
  58. local function updateDamage()
  59. local playerPets = playersFolder[player.Name]:GetChildren()
  60. for _, pet in ipairs(playerPets) do
  61. local attackValue = pet.Attack.Value
  62. if attackValue then
  63. local drop = attackValue.Parent
  64. local currentPoints = drop.CurrentPoints
  65. currentPoints.Value = math.max(currentPoints.Value - pet.Damage.Value, 0)
  66. if currentPoints.Value == 0 then
  67. for _, pet in pairs(playerPets) do
  68. pet.Attack.Value = nil
  69. end
  70. destroyDrop(drop)
  71. end
  72. end
  73. end
  74. end
  75. local function updateDropDisplay()
  76. local drops = workspace:WaitForChild("Drops"):GetDescendants()
  77. for _, drop in pairs(drops) do
  78. if drop:IsA("Model") then
  79. local display = drop:FindFirstChild("Display")
  80. local bar = display.Background.Bar
  81. local displayText = display.Background.Amount
  82. displayText.Text = tostring(drop.CurrentPoints.Value)
  83. bar:TweenSize(
  84. UDim2.fromScale(drop.CurrentPoints.Value / drop.MaxPoints.Value, 1),
  85. Enum.EasingDirection.Out,
  86. Enum.EasingStyle.Sine,
  87. 0.3)
  88. end
  89. end
  90. end
  91. task.spawn(function()
  92. while task.wait(1) do
  93. updateDamage()
  94. updateDropDisplay()
  95. end
  96. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement