Advertisement
giganciprogramowania

lekcja 6 Drops Client

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