Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Services
- local collectionService = game:GetService("CollectionService")
- local Players = game:GetService("Players")
- local RepStore = game:GetService("ReplicatedStorage")
- local TweenService = game:GetService("TweenService")
- -- Models
- local arrow = RepStore:WaitForChild("Pointing Arrow")
- -- Model parts
- local arrowPart = arrow.PrimaryPart
- -- Main objects
- local Player = Players.LocalPlayer
- -- Player folders
- local leaderstats = Player:WaitForChild("leaderstats")
- -- Player values
- local stageValue = leaderstats:WaitForChild("Stage")
- -- Arrays
- local checkpoints = {}
- -- Assignation
- arrow.Parent = workspace
- -- Loops
- for _,checkpoint in pairs(collectionService:GetTagged("checkpoint")) do
- checkpoint:WaitForChild("Stage")
- table.insert(checkpoints,checkpoint)
- end
- -- Function calls
- table.sort(
- checkpoints,
- function(a,b)
- return a.Stage.Value < b.Stage.Value
- end
- )
- -- TweenInfo
- local tweenInfo = TweenInfo.new(
- 1,
- Enum.EasingStyle.Quad,
- Enum.EasingDirection.InOut,
- -1, -- (-1 makes the tween loop infinitely)
- true, -- Set the reversal to true
- 0
- )
- -- Tweens
- local currentTween
- -- Vectors
- local arrowHeightOffset = Vector3.new(0, 9, 0)
- local arrowRiseVector = Vector3.new(0, 2, 0)
- -- Functions
- local function placeArrow(currentStage)
- if currentStage >= #checkpoints then
- arrow.Parent = RepStore
- else
- arrow.Parent = workspace
- if currentTween then
- currentTween:Cancel()
- end
- local nextCFrame = checkpoints[currentStage + 1].CFrame + arrowHeightOffset
- arrow:SetPrimaryPartCFrame(nextCFrame - arrowRiseVector)
- currentTween = TweenService:Create(
- arrowPart,
- tweenInfo,
- {CFrame = nextCFrame + arrowRiseVector}
- )
- currentTween:Play()
- end
- end
- -- Event listeners
- stageValue.Changed:Connect(placeArrow)
- -- Function calls
- placeArrow(stageValue.Value or 0)
Advertisement
Add Comment
Please, Sign In to add comment