ttvmetroidd

energy system

Jun 19th, 2024
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. local repstorage = game:GetService("ReplicatedStorage")
  2.  
  3. local Events = repstorage.Events
  4. local anims = script.Animations
  5.  
  6. local module = {}
  7. local dashDebounces = {}
  8.  
  9. local DashEnergy = 30
  10. Events.Dash.OnServerEvent:Connect(function(player)
  11. if(player.Energy.value - DashEnergy) < 0 then
  12. return
  13. end
  14. if dashDebounces[player] then
  15. return
  16. end
  17. local character = player.Character or player.CharacterAdded:Wait()
  18. if character == nil then
  19. return
  20. end
  21. local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  22. local humanoid = character:FindFirstChild("Humanoid")
  23. if humanoid == nil then
  24. return
  25. end
  26. if humanoidRootPart == nil or humanoid.Health == 0 then
  27. return
  28. end
  29. dashDebounces[player] = true
  30. player.Energy.Value -= DashEnergy
  31. local dashanim = humanoid.Animator:LoadAnimation(anims.Dash)
  32. dashanim:Play()
  33.  
  34. local dashTrail = script.DashTrail:Clone()
  35. dashTrail.Parent = character.UpperTorso
  36. dashTrail.Attachment0 = character.LowerTorso.WaistBackAttachment
  37. dashTrail.Attachment1 = character.Head.NeckRigAttachment
  38.  
  39. local vectorForce: VectorForce = Instance.new("VectorForce")
  40. vectorForce.Attachment0 = humanoidRootPart.RootRigAttachment
  41. vectorForce.Force = humanoidRootPart.CFrame.LookVector * 15000
  42. vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
  43. vectorForce.Parent = humanoidRootPart
  44.  
  45. task.delay(0.5, function()
  46. dashTrail:Destroy()
  47. dashanim:Stop()
  48. end)
  49.  
  50. task.delay(0.2, function()
  51. vectorForce:Destroy()
  52. end)
  53.  
  54. task.wait(1)
  55. if dashDebounces[player] then
  56. dashDebounces[player] = nil
  57. end
  58. task.delay(4, function()
  59. for i = 1, DashEnergy do
  60. player.Energy.Value = math.min(100, player.Energy.Value + 1)
  61. task.wait(5/DashEnergy)
  62. end
  63. end)
  64. end)
  65.  
  66. return module
Advertisement
Add Comment
Please, Sign In to add comment