Advertisement
3DCreator

StageGui LocalScript

Mar 13th, 2021
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. local UI = script.Parent
  2.  
  3. local player = game.Players.LocalPlayer
  4.  
  5. local checkpoints = workspace:WaitForChild("Checkpoints")
  6.  
  7. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  8. local Teleport = ReplicatedStorage:WaitForChild("Teleport")
  9.  
  10. local Level = UI:WaitForChild("Stage")
  11. local Previous = UI:WaitForChild("Previous")
  12. local Next = UI:WaitForChild("Next")
  13. local CurrentValue = UI:WaitForChild("CurrentStage")
  14.  
  15. local function previousLevel()
  16.     if CurrentValue.Value ~= 1 then
  17.         CurrentValue.Value = CurrentValue.Value - 1
  18.         Level.Text = CurrentValue.Value
  19.         Teleport:FireServer(checkpoints:GetChildren()[CurrentValue.Value])
  20.     end
  21. end
  22.  
  23. local function nextLevel()
  24.     if CurrentValue.Value ~= #checkpoints:GetChildren() then
  25.         if (CurrentValue.Value + 1) <= player.leaderstats.Stage.Value then
  26.             CurrentValue.Value = CurrentValue.Value + 1
  27.             Level.Text = CurrentValue.Value
  28.             Teleport:FireServer(checkpoints:GetChildren()[CurrentValue.Value])
  29.         end
  30.     end
  31. end
  32.  
  33. Previous.MouseButton1Click:Connect(function()
  34.     previousLevel()
  35. end)
  36.  
  37. Next.MouseButton1Click:Connect(function()
  38.     nextLevel()
  39. end)
  40.  
  41. CurrentValue.Value = player:WaitForChild("leaderstats").Stage.Value
  42. Level.Text = CurrentValue.Value
  43.  
  44. player.leaderstats.Stage:GetPropertyChangedSignal("Value"):Connect(function()
  45.     CurrentValue.Value = player.leaderstats.Stage.Value
  46.     Level.Text = CurrentValue.Value
  47. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement