TheHeckingDeveloper

Arrow

Jul 2nd, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. -- Services
  2. local collectionService = game:GetService("CollectionService")
  3. local Players = game:GetService("Players")
  4. local RepStore = game:GetService("ReplicatedStorage")
  5. local TweenService = game:GetService("TweenService")
  6.  
  7. -- Models
  8. local arrow = RepStore:WaitForChild("Pointing Arrow")
  9.  
  10. -- Model parts
  11. local arrowPart = arrow.PrimaryPart
  12.  
  13. -- Main objects
  14. local Player = Players.LocalPlayer
  15.  
  16. -- Player folders
  17. local leaderstats = Player:WaitForChild("leaderstats")
  18.  
  19. -- Player values
  20. local stageValue = leaderstats:WaitForChild("Stage")
  21.  
  22. -- Arrays
  23. local checkpoints = {}
  24.  
  25. -- Assignation
  26. arrow.Parent = workspace
  27.  
  28. -- Loops
  29. for _,checkpoint in pairs(collectionService:GetTagged("checkpoint")) do
  30.     checkpoint:WaitForChild("Stage")
  31.    
  32.     table.insert(checkpoints,checkpoint)
  33. end
  34.  
  35. -- Function calls
  36. table.sort(
  37.     checkpoints,
  38.    
  39.     function(a,b)
  40.         return a.Stage.Value < b.Stage.Value
  41.     end
  42. )
  43.  
  44. -- TweenInfo
  45. local tweenInfo = TweenInfo.new(
  46.     1,
  47.     Enum.EasingStyle.Quad,
  48.     Enum.EasingDirection.InOut,
  49.     -1, -- (-1 makes the tween loop infinitely)
  50.     true, -- Set the reversal to true
  51.     0
  52. )
  53.  
  54. -- Tweens
  55. local currentTween
  56.  
  57. -- Vectors
  58. local arrowHeightOffset = Vector3.new(0, 9, 0)
  59. local arrowRiseVector = Vector3.new(0, 2, 0)
  60.  
  61. -- Functions
  62. local function placeArrow(currentStage)
  63.     if currentStage >= #checkpoints then
  64.         arrow.Parent = RepStore
  65.     else
  66.         arrow.Parent = workspace
  67.        
  68.         if currentTween  then
  69.             currentTween:Cancel()
  70.         end
  71.        
  72.         local nextCFrame = checkpoints[currentStage + 1].CFrame + arrowHeightOffset
  73.         arrow:SetPrimaryPartCFrame(nextCFrame - arrowRiseVector)
  74.        
  75.         currentTween = TweenService:Create(
  76.             arrowPart,
  77.             tweenInfo,
  78.             {CFrame = nextCFrame + arrowRiseVector}
  79.         )
  80.        
  81.         currentTween:Play()
  82.     end
  83. end
  84.  
  85. -- Event listeners
  86. stageValue.Changed:Connect(placeArrow)
  87.  
  88. -- Function calls
  89. placeArrow(stageValue.Value or 0)
Advertisement
Add Comment
Please, Sign In to add comment