Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---[CHECKPOINTS]-------------------------------------
- local Players = game:GetService('Players')
- local Obby = {}
- Obby.Checkpoints = {}
- Obby.Players = {}
- function Obby:Touched(Character, Part)
- local Player = Players:GetPlayerFromCharacter(Character)
- local PlayerInfo = self.Players[Player and Player.UserId or 0]
- local CurrentLevel = PlayerInfo.Level
- local NextLevel = CurrentLevel + 1
- local StageInfo = self.Checkpoints[NextLevel] or {}
- if StageInfo.Part and StageInfo.Part == Part and (Character.PrimaryPart.Position-Part.Position).Magnitude<=8 then
- if tick() - PlayerInfo.LastLeveled < 3 and StageInfo.Level>=NextLevel then
- PlayerInfo.Counts = PlayerInfo.Counts + 1
- if PlayerInfo.Counts >= 3 then
- return Player:Kick('you went to next stage three times too fast ...')
- end
- end
- if StageInfo.Level == NextLevel then
- PlayerInfo.LastLeveled = tick()
- PlayerInfo.Stage.Value = NextLevel
- PlayerInfo.Level = NextLevel
- end
- end
- end
- function Obby:CreateStats(Player)
- local Stats = Instance.new('Folder')
- Stats.Name = 'leaderstats'
- Stats.Parent = Player
- local Level = Instance.new('IntValue')
- Level.Name = 'Stage'
- Level.Value = 0
- Level.Parent = Stats
- local Data = self.Players[Player.UserId]
- Level.Value = Data.Level
- Data.Stage = Level
- end
- function Obby.SetupCharacter(Character)
- wait()
- Character:WaitForChild'HumanoidRootPart'
- local Player = Players:GetPlayerFromCharacter(Character)
- local PlayerInfo = Obby.Players[Player.UserId]
- local Checkpoint = Obby.Checkpoints[PlayerInfo.Level]
- if Checkpoint then
- Character:SetPrimaryPartCFrame(CFrame.new(Checkpoint.Part.Position) * CFrame.new(0,3,0))
- end
- end
- function Obby.SetupPlayer(Player)
- local Data = Obby.Players[Player.UserId]
- Obby.Players[Player.UserId] = Data or {
- ['Level'] = 0;
- ['LastLeveled'] = 0;
- ['Counts'] = 0;
- };
- local Character = Player.Character or Player.CharacterAdded:Wait()
- Obby.SetupCharacter(Character)
- Player.CharacterAdded:Connect(Obby.SetupCharacter)
- return not Data and Obby:CreateStats(Player)
- end
- function Obby.RemovePlayer(Player)
- local Data = Obby.Players[Player.UserId]
- if Data then
- Obby.Players[Player.UserId] = nil
- end
- end
- function Obby:SetupCheckpoint(Part)
- local Level = tonumber(Part.Name)
- self.Checkpoints[Level] = {
- ['Part'] = Part;
- ['Level'] = Level;
- }
- Part.Touched:Connect(function(Hit)
- local Character = Hit and Hit.Parent
- local Humanoid = Character and Character:FindFirstChildOfClass'Humanoid'
- if Humanoid and Humanoid.Health > 0 then
- self:Touched(Character, Part)
- end
- end)
- end
- Players.PlayerAdded:Connect(Obby.SetupPlayer)
- Players.PlayerRemoving:Connect(Obby.RemovePlayer)
- for _, Player in next, Players:GetPlayers() do
- Obby.SetupPlayer(Player)
- end
- local Checkpoints = workspace.Checkpoints
- for _, Checkpoint in next, Checkpoints:GetChildren() do
- Obby:SetupCheckpoint(Checkpoint)
- end
Advertisement
Advertisement