Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Services.
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Players = game:GetService("Players")
- local Workspace = game:GetService("Workspace")
- local CollectionService = game:GetService("CollectionService")
- local RunService = game:GetService("RunService")
- local TweenService = game:GetService("TweenService")
- local Obby = {}
- function Obby.Leaderstats(player: Player)
- local leaderstats = Instance.new("Folder")
- leaderstats.Name = "leaderstats"
- leaderstats.Parent = player
- local stage = Instance.new("NumberValue")
- stage.Name = "Stage"
- stage.Value = 1
- stage.Parent = leaderstats
- local deaths = Instance.new("NumberValue")
- deaths.Name = "Deaths"
- deaths.Value = 0
- deaths.Parent = leaderstats
- -- creates a "folder" and then names the "folder > leaderstats"; then assigns it to the “player”; it creates a "Numbervalue" in the “leaderstatsfolder”; it names the "Numbervalue > Stage" and sets "value > 1.”
- end
- function Obby.Respawn(player: Player)
- local leaderstats = player:FindFirstChild("leaderstats") -- if “leaderstats,” then
- if not leaderstats then return end -- end if no "leaderstats."
- local Stages = leaderstats:FindFirstChild("Stage") -- if “Stages,” then
- if not Stages then return end -- end if no "Stages."
- local stage = Stages.Value
- for _, spawn in ipairs(CollectionService:GetTagged("CheckpointSpawn")) do
- if spawn:IsA("SpawnLocation") and spawn:GetAttribute("Stage") == stage then
- local character = player.Character -- get "character."
- if character then -- if “character,” then
- character:PivotTo(spawn.CFrame)
- end
- break
- end
- end
- -- this script gets the player’s current “stage”; loops through all the "spawnlocations" tagged as "CheckpointSpawn" with "Collectionservice"; if the spawn location's "stage" matches the player’s current “stage“; it teleports the player to that “spawnlocation.”
- end
- function Obby.Death(player: Player, character: Model)
- local deathMessages = { -- This is the list of "messages" that can "appear" when the player "dies."
- "You Died.",
- "Better luck next time.",
- "That's unlucky.",
- "Oops!",
- "Try again!",
- "Not like this...",
- "Close one!",
- "One more time!",
- }
- local humanoid = character:FindFirstChildOfClass("Humanoid") -- if “humanoid,” then
- if not humanoid then return end -- end if no "humanoid."
- humanoid.Died:Connect(function()
- local leaderstats = player:FindFirstChild("leaderstats") -- if “leaderstats,” then
- if not leaderstats then return end -- end if no "leaderstats."
- local deaths = leaderstats:FindFirstChild("Deaths") -- if “deaths,” then
- if not deaths then return end -- end if no "deaths."
- if deaths then -- if “leaderstats,” then
- deaths.Value += 1 -- then increase the deaths by "1."
- end
- Obby.ShowUIMessage(player, "DeathUI", deathMessages) -- Shows a "random" UI Message when the player "dies."
- end)
- -- when a player dies the "humanoid.died" event is called; it increases the value of the player's "deaths"; it also shows a "UI" message.
- end
- function Obby.Portal(portal: BasePart, destination: BasePart)
- portal.Touched:Connect(function(other)
- local char = other.Parent -- if “character,” then
- if not char:FindFirstChildOfClass("Humanoid") then return end -- end if no “humanoid.”
- local root = char:FindFirstChild("HumanoidRootPart") -- get “HumanoidRootPart.”
- if root then -- if “root,” then.
- root.CFrame = destination * CFrame.new(0, 3, 0) -- Teleports the player to the desired “destination.”
- end
- end)
- -- adds a "touched.event" to the “portal” when the player touches the “portal”; it teleports the player to the “destination.”
- end
- function Obby.Checkpoints()
- local spawns = CollectionService:GetTagged("CheckpointSpawn") -- Get all parts tagged with "CheckpointSpawn" using “CollectionService.”
- for _, spawn in ipairs(spawns) do -- Loop through each “checkpoint.”
- spawn.Touched:Connect(function(otherPart: BasePart)
- local character = otherPart.Parent -- if “character,” then
- if not character or not character:IsA("Model") then return end -- end if no "character."
- local player = Players:GetPlayerFromCharacter(character) -- if “player,” then
- if not player then return end -- end if no "player."
- local spawnTime = character:GetAttribute("SpawnTime") -- “debounce.”
- if spawnTime and tick() - spawnTime < 2 then return end
- local leaderstats = player:FindFirstChild("leaderstats") -- if “leaderstats,” then
- if not leaderstats then return end -- end if no "leaderstats."
- local stageValue = leaderstats:FindFirstChild("Stage") -- if “stagevalue,” then
- if not stageValue then return end -- end if no "stagevalue".
- local newStage = tonumber(spawn:GetAttribute("Stage"))
- if newStage and newStage > stageValue.Value then
- stageValue.Value = newStage
- Obby.ShowUIMessage(player, "CheckpointUI")
- end
- end)
- end
- -- when a player touches a “checkpoint"; it checks if the player is ahead of the current “stage”; it updates the player’s stage and displays a ”UI" message.
- end
- function Obby.KillParts()
- local killParts = CollectionService:GetTagged("Kill") -- get all parts tagged with "Kill" using “CollectionService.”
- for _, part in ipairs(killParts) do -- loop through each tagged as “Kill.”
- part.Touched:Connect(function(otherPart: BasePart)
- local character = otherPart.Parent -- if “character,” then
- if not character then return end -- end if no “character.”
- if character and character:IsA("Model") then
- local humanoid = character:FindFirstChildOfClass("Humanoid") -- if “humanoid,” then
- if humanoid and humanoid.Health > 0 then -- if "humanoid" and “alive,” then
- humanoid:TakeDamage(100)
- end
- end
- end)
- end
- -- gets all the parts that have the tag “Kill” using "CollectionService"; then it loops through each part that has the tag “Kill”; then it adds a "touched.event" to every part that has the tag “Kill”; if a player touches a part that has the tag “Kill"; it does damage to the player's “humanoid.”
- end
- function Obby.FakePlatforms()
- local fakePlatforms = CollectionService:GetTagged("FakePlatform") -- get all parts tagged with "FakePlatform" using “CollectionService”.
- for _, part in ipairs(fakePlatforms) do -- loop through each “fakePlatform.”
- part.Touched:Connect(function(otherPart)
- if part:GetAttribute("IsFalling") then return end -- "debounce"
- local character = otherPart.Parent -- get ”character.”
- if not character or not character:IsA("Model") then return end -- end if no "character."
- local humanoid = character:FindFirstChildOfClass("Humanoid") -- get ”humanoid.”
- if not humanoid or humanoid.Health <= 0 then return end -- end if no "humanoid."
- part:SetAttribute("IsFalling", true) -- "debounce"
- part.Transparency = 1
- part.CanCollide = false
- local resetTime = part:GetAttribute("ResetTime") or 3
- task.wait(resetTime)
- part.Transparency = 0.35
- part.CanCollide = true
- part:SetAttribute("IsFalling", false)
- end)
- end
- -- gets all the parts that have the tag "FakePlatform" using "CollectionService"; it loops through each part that has the tag “FakePlatform”; it adds a "touched.event" to every part that has the tag “FakePlatform”; if a player touches the part that has the tag “FakePlatform”; it makes the part invisible and non-collidable for a certain amount of time; then it resets the part to its original state.
- end
- function Obby.MovingPlatform()
- local movingPlatforms = CollectionService:GetTagged("MovingPlatform") -- get all parts tagged with "MovingPlatform" using “CollectionService.”
- for _, platform in ipairs(movingPlatforms) do -- loop through each ”movingPlatforms.”
- local targetPosition = platform:GetAttribute("TargetPosition") -- get ”TargetPosition.”
- if not targetPosition then return end -- end if no "targetPosition."
- local moveTime = platform:GetAttribute("MoveTime") or 3
- local endPos = Vector3.new(targetPosition.X, targetPosition.Y, targetPosition.Z)
- local tweenInfo = TweenInfo.new(moveTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true)
- local tween = TweenService:Create(platform, tweenInfo, {Position = endPos})
- tween:Play()
- end
- -- gets all the parts that have the tag "MovingPlatform" using "CollectionService"; it loops through each part that has the tag “MovingPlatform”; it gets the target position and move time from the part's attributes; it creates a tween to move the platform to the target position and plays it in a loop.
- end
- function Obby.ColorChangingPlatform()
- local ColorChangingPlatforms = CollectionService:GetTagged("ColorChanging") -- get all parts tagged with "ColorChanging" using “CollectionService.”
- for _, platform in ipairs(ColorChangingPlatforms) do -- loop through each "ColorChangingPlatform."
- local originalColor = platform.Color
- local redDuration = platform:GetAttribute("RedDuration") or 2
- local originalDuration = platform:GetAttribute("OriginalDuration") or 2
- local function ChangeColor()
- while true do
- platform.Color = Color3.fromRGB(255, 0, 0)
- task.wait(redDuration)
- platform.Color = originalColor
- task.wait(originalDuration)
- end
- end
- task.spawn(ChangeColor)
- platform.Touched:Connect(function(otherPart)
- local character = otherPart.Parent -- if “character,” then
- if not character or not character:IsA("Model") then return end -- end if no "character."
- local humanoid = character:FindFirstChildOfClass("Humanoid") -- if “humanoid,” then
- if not humanoid or humanoid.Health <= 0 then return end -- end if no "humanoid."
- if platform.Color == Color3.fromRGB(255, 0, 0) then
- humanoid:TakeDamage(100)
- end
- end)
- end
- -- gets all the parts that have the tag "ColorChanging" using "CollectionService"; it loops through each part that has the tag “ColorChanging”; it changes the color of the platform to red for a certain duration and then back to its original color; it also adds a "touched.event" to the platform that damages the player if they touch it while it's red.
- end
- function Obby.ShowUIMessage(player, guiName, messages)
- local playerGui = player:FindFirstChildOfClass("PlayerGui") -- if “playerGui,” then
- if not playerGui then return end -- end if no "playerGui."
- local ui = playerGui:FindFirstChild(guiName) or (ReplicatedStorage:FindFirstChild(guiName) and ReplicatedStorage[guiName]:Clone()) -- if “ui,” then
- if not ui then return end -- end if no "ui."
- ui.Parent = playerGui
- local label = ui:FindFirstChildOfClass("TextLabel") -- if “label,” then
- if not label then return end -- end if no "label."
- if messages and #messages > 0 then -- if “messages,” then
- label.Text = messages[math.random(1, #messages)]
- end
- label.Visible = true
- label.TextTransparency = 1
- for i = 0, 1, 0.1 do
- label.TextTransparency = 1 - i
- task.wait(0.03)
- end
- task.wait(1.5)
- for i = 0, 1, 0.1 do
- label.TextTransparency = i
- task.wait(0.03)
- end
- label.Visible = false
- -- gets the player's "PlayerGui"; if the player doesn't have a "PlayerGui," it returns; it checks if the UI exists in the player's "PlayerGui" or clones it from "ReplicatedStorage"; it sets the UI's parent to the player's "PlayerGui"; it finds a "TextLabel" in the UI; if it doesn't find a "TextLabel," it returns; it sets the text of the label to a random message from the provided messages; it fades in the label, waits for 1.5 seconds, and then fades it out.
- end
- return Obby
Advertisement
Add Comment
Please, Sign In to add comment