MysteriaFool

Obby

Jul 25th, 2025 (edited)
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.11 KB | None | 0 0
  1. -- Services.
  2. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  3. local Players = game:GetService("Players")
  4. local Workspace = game:GetService("Workspace")
  5. local CollectionService = game:GetService("CollectionService")
  6. local RunService = game:GetService("RunService")
  7. local TweenService = game:GetService("TweenService")
  8.  
  9. local Obby = {}
  10.  
  11. function Obby.Leaderstats(player: Player)
  12.     local leaderstats = Instance.new("Folder")
  13.     leaderstats.Name = "leaderstats"
  14.     leaderstats.Parent = player
  15.  
  16.     local stage = Instance.new("NumberValue")
  17.     stage.Name = "Stage"
  18.     stage.Value = 1
  19.     stage.Parent = leaderstats
  20.  
  21.     local deaths = Instance.new("NumberValue")
  22.     deaths.Name = "Deaths"
  23.     deaths.Value = 0
  24.     deaths.Parent = leaderstats
  25.    
  26.     -- 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.”
  27. end
  28.  
  29. function Obby.Respawn(player: Player)
  30.     local leaderstats = player:FindFirstChild("leaderstats") -- if “leaderstats,” then
  31.     if not leaderstats then return end -- end if no "leaderstats."
  32.  
  33.     local Stages = leaderstats:FindFirstChild("Stage") -- if “Stages,” then
  34.     if not Stages then return end -- end if no "Stages."
  35.  
  36.     local stage = Stages.Value
  37.  
  38.     for _, spawn in ipairs(CollectionService:GetTagged("CheckpointSpawn")) do
  39.         if spawn:IsA("SpawnLocation") and spawn:GetAttribute("Stage") == stage then
  40.  
  41.             local character = player.Character -- get "character."
  42.             if character then -- if “character,” then
  43.                 character:PivotTo(spawn.CFrame)
  44.             end
  45.  
  46.             break
  47.         end
  48.     end
  49.     -- 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.”
  50. end
  51.  
  52. function Obby.Death(player: Player, character: Model)  
  53.     local deathMessages = { -- This is the list of "messages" that can "appear" when the player "dies."
  54.     "You Died.",
  55.     "Better luck next time.",
  56.     "That's unlucky.",
  57.     "Oops!",
  58.     "Try again!",
  59.     "Not like this...",
  60.     "Close one!",
  61.     "One more time!",
  62.    }
  63.  
  64.     local humanoid = character:FindFirstChildOfClass("Humanoid") -- if “humanoid,” then
  65.     if not humanoid then return end -- end if no "humanoid."
  66.  
  67.     humanoid.Died:Connect(function()
  68.         local leaderstats = player:FindFirstChild("leaderstats") -- if “leaderstats,” then
  69.         if not leaderstats then return end -- end if no "leaderstats."
  70.        
  71.         local deaths = leaderstats:FindFirstChild("Deaths") -- if “deaths,” then
  72.         if not deaths then return end -- end if no "deaths."
  73.  
  74.         if deaths then -- if “leaderstats,” then
  75.             deaths.Value += 1 -- then increase the deaths by "1."
  76.         end
  77.  
  78.         Obby.ShowUIMessage(player, "DeathUI", deathMessages) -- Shows a "random" UI Message when the player "dies."
  79.     end)
  80.     -- 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.
  81. end
  82.  
  83. function Obby.Portal(portal: BasePart, destination: BasePart)
  84.     portal.Touched:Connect(function(other)
  85.         local char = other.Parent -- if “character,” then
  86.         if not char:FindFirstChildOfClass("Humanoid") then return end -- end if no “humanoid.”
  87.  
  88.         local root = char:FindFirstChild("HumanoidRootPart") -- get “HumanoidRootPart.”
  89.         if root then -- if “root,” then.
  90.             root.CFrame = destination * CFrame.new(0, 3, 0) -- Teleports the player to the desired “destination.”
  91.         end
  92.     end)
  93.     -- adds a "touched.event" to the “portal” when the player touches the “portal”; it teleports the player to the “destination.”
  94. end
  95.  
  96. function Obby.Checkpoints()
  97.     local spawns = CollectionService:GetTagged("CheckpointSpawn") -- Get all parts tagged with "CheckpointSpawn" using “CollectionService.”
  98.  
  99.     for _, spawn in ipairs(spawns) do -- Loop through each “checkpoint.”
  100.         spawn.Touched:Connect(function(otherPart: BasePart)
  101.             local character = otherPart.Parent -- if “character,” then
  102.             if not character or not character:IsA("Model") then return end -- end if no "character."
  103.  
  104.             local player = Players:GetPlayerFromCharacter(character) -- if “player,” then
  105.             if not player then return end -- end if no "player."
  106.  
  107.             local spawnTime = character:GetAttribute("SpawnTime") -- “debounce.”
  108.             if spawnTime and tick() - spawnTime < 2 then return end
  109.  
  110.             local leaderstats = player:FindFirstChild("leaderstats") -- if “leaderstats,” then
  111.             if not leaderstats then return end -- end if no "leaderstats."
  112.  
  113.             local stageValue = leaderstats:FindFirstChild("Stage") -- if “stagevalue,” then
  114.             if not stageValue then return end -- end if no "stagevalue".
  115.  
  116.             local newStage = tonumber(spawn:GetAttribute("Stage"))
  117.             if newStage and newStage > stageValue.Value then
  118.                 stageValue.Value = newStage
  119.                 Obby.ShowUIMessage(player, "CheckpointUI")
  120.             end
  121.         end)
  122.     end
  123.     -- 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.
  124. end
  125.  
  126. function Obby.KillParts()  
  127.     local killParts = CollectionService:GetTagged("Kill") -- get all parts tagged with "Kill" using “CollectionService.”
  128.    
  129.     for _, part in ipairs(killParts) do -- loop through each tagged as “Kill.”
  130.  
  131.         part.Touched:Connect(function(otherPart: BasePart)
  132.             local character = otherPart.Parent -- if “character,” then
  133.             if not character then return end -- end if no “character.”
  134.             if character and character:IsA("Model") then
  135.                 local humanoid = character:FindFirstChildOfClass("Humanoid") -- if “humanoid,” then
  136.                 if humanoid and humanoid.Health > 0 then -- if "humanoid" and “alive,” then
  137.                     humanoid:TakeDamage(100)
  138.                 end
  139.             end
  140.         end)
  141.     end
  142.     -- 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.”
  143. end
  144.  
  145. function Obby.FakePlatforms()
  146.     local fakePlatforms = CollectionService:GetTagged("FakePlatform") -- get all parts tagged with "FakePlatform" using “CollectionService”.
  147.  
  148.     for _, part in ipairs(fakePlatforms) do -- loop through each “fakePlatform.”
  149.  
  150.             part.Touched:Connect(function(otherPart)
  151.  
  152.                 if part:GetAttribute("IsFalling") then return end -- "debounce"
  153.  
  154.                 local character = otherPart.Parent -- get ”character.”
  155.                 if not character or not character:IsA("Model") then return end -- end if no "character."
  156.  
  157.                 local humanoid = character:FindFirstChildOfClass("Humanoid") -- get ”humanoid.”
  158.                 if not humanoid or humanoid.Health <= 0 then return end -- end if no "humanoid."
  159.  
  160.                 part:SetAttribute("IsFalling", true) -- "debounce"
  161.  
  162.                 part.Transparency = 1
  163.                 part.CanCollide = false
  164.  
  165.                 local resetTime = part:GetAttribute("ResetTime") or 3
  166.                 task.wait(resetTime)
  167.  
  168.                 part.Transparency = 0.35
  169.                 part.CanCollide = true
  170.  
  171.                 part:SetAttribute("IsFalling", false)
  172.             end)
  173.         end
  174.         -- 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.
  175. end
  176.  
  177. function Obby.MovingPlatform()
  178.     local movingPlatforms = CollectionService:GetTagged("MovingPlatform") -- get all parts tagged with "MovingPlatform" using “CollectionService.”
  179.  
  180.     for _, platform in ipairs(movingPlatforms) do -- loop through each ”movingPlatforms.”
  181.  
  182.         local targetPosition = platform:GetAttribute("TargetPosition") -- get ”TargetPosition.”
  183.         if not targetPosition then return end -- end if no "targetPosition."
  184.  
  185.         local moveTime = platform:GetAttribute("MoveTime") or 3
  186.  
  187.         local endPos = Vector3.new(targetPosition.X, targetPosition.Y, targetPosition.Z)
  188.         local tweenInfo = TweenInfo.new(moveTime, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true)
  189.         local tween = TweenService:Create(platform, tweenInfo, {Position = endPos})
  190.         tween:Play()
  191.     end
  192.     -- 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.
  193. end
  194.  
  195. function Obby.ColorChangingPlatform()
  196.     local ColorChangingPlatforms = CollectionService:GetTagged("ColorChanging") -- get all parts tagged with "ColorChanging" using “CollectionService.”
  197.  
  198.     for _, platform in ipairs(ColorChangingPlatforms) do -- loop through each "ColorChangingPlatform."
  199.         local originalColor = platform.Color
  200.  
  201.         local redDuration = platform:GetAttribute("RedDuration") or 2
  202.         local originalDuration = platform:GetAttribute("OriginalDuration") or 2
  203.        
  204.         local function ChangeColor()
  205.             while true do
  206.                 platform.Color = Color3.fromRGB(255, 0, 0)
  207.                 task.wait(redDuration)
  208.                
  209.                 platform.Color = originalColor
  210.                 task.wait(originalDuration)
  211.             end
  212.         end
  213.  
  214.         task.spawn(ChangeColor)
  215.  
  216.         platform.Touched:Connect(function(otherPart)
  217.             local character = otherPart.Parent -- if “character,” then
  218.             if not character or not character:IsA("Model") then return end -- end if no "character."
  219.  
  220.             local humanoid = character:FindFirstChildOfClass("Humanoid") -- if “humanoid,” then
  221.             if not humanoid or humanoid.Health <= 0 then return end -- end if no "humanoid."
  222.  
  223.             if platform.Color == Color3.fromRGB(255, 0, 0) then
  224.                 humanoid:TakeDamage(100)
  225.             end
  226.         end)
  227.     end
  228.     -- 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.
  229. end
  230.  
  231. function Obby.ShowUIMessage(player, guiName, messages)
  232.     local playerGui = player:FindFirstChildOfClass("PlayerGui") -- if “playerGui,” then
  233.     if not playerGui then return end -- end if no "playerGui."
  234.  
  235.     local ui = playerGui:FindFirstChild(guiName) or (ReplicatedStorage:FindFirstChild(guiName) and ReplicatedStorage[guiName]:Clone()) -- if “ui,” then
  236.     if not ui then return end -- end if no "ui."
  237.  
  238.     ui.Parent = playerGui
  239.  
  240.     local label = ui:FindFirstChildOfClass("TextLabel") -- if “label,” then
  241.     if not label then return end -- end if no "label."
  242.  
  243.     if messages and #messages > 0 then -- if “messages,” then
  244.         label.Text = messages[math.random(1, #messages)]
  245.     end
  246.  
  247.     label.Visible = true
  248.     label.TextTransparency = 1
  249.     for i = 0, 1, 0.1 do
  250.         label.TextTransparency = 1 - i
  251.         task.wait(0.03)
  252.     end
  253.  
  254.     task.wait(1.5)
  255.  
  256.     for i = 0, 1, 0.1 do
  257.         label.TextTransparency = i
  258.         task.wait(0.03)
  259.     end
  260.  
  261.     label.Visible = false
  262.  
  263.     -- 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.
  264. end
  265.  
  266. return Obby
Advertisement
Add Comment
Please, Sign In to add comment
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy