Advertisement
fishinthebox

Untitled

Apr 28th, 2025
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.05 KB | None | 0 0
  1. local Players = game.Players
  2.  
  3. local RS = game:GetService("ReplicatedStorage")
  4. local Events = RS.RemoteEvents
  5.  
  6. local ProfileStore = require(game.ReplicatedStorage.ProfileStore)
  7.  
  8. local function RestartChar(Char, Plr: Player)
  9.     print("YES")
  10.    
  11.     Plr:SetAttribute("Spectating", false)
  12.  
  13.     local Hum: Humanoid = Char:FindFirstChildOfClass("Humanoid") or Char:WaitForChild("Humanoid")
  14.  
  15.     Hum.Died:Once(function()
  16.        
  17.         if workspace.Values.GameActive.Value == false then
  18.             task.wait(2)
  19.             Plr:LoadCharacter()
  20.             return
  21.         end
  22.        
  23.         Plr:SetAttribute("Spectating", true)
  24.        
  25.         local AllPlayersDead = true
  26.         for _, plr in Players:GetPlayers() do
  27.             if not plr.Character then continue end
  28.             local Hum: Humanoid = Char:FindFirstChildOfClass("Humanoid") or Char:WaitForChild("Humanoid")
  29.            
  30.             if Hum.Health > 0 then
  31.                 AllPlayersDead = false
  32.             end
  33.         end
  34.        
  35.         if AllPlayersDead and workspace.Values.GameActive.Value == true then
  36.             workspace.Values.GameActive.Value = false
  37.             workspace.Enemies:ClearAllChildren()
  38.             Events.SendMessage:FireAllClients("[System]: All players have died. Restarting...")
  39.             task.wait(5)
  40.            
  41.             for _, plr in Players:GetPlayers() do
  42.                 plr:LoadCharacter()
  43.             end
  44.         end
  45.        
  46.         task.wait(26)
  47.         if Plr and Plr.Parent and Plr:GetAttribute("Spectating") == true then
  48.             Plr:LoadCharacter()
  49.         end
  50.     end)
  51. end
  52.  
  53. game.Players.PlayerAdded:Connect(function(plr)
  54.     plr:LoadCharacter()
  55.     RestartChar(plr.Character, plr)
  56.    
  57.     plr.CharacterAdded:Connect(function(char)
  58.         RestartChar(char, plr)
  59.         local ff = Instance.new("ForceField", char)
  60.         game.Debris:AddItem(ff, 3)
  61.     end)
  62.    
  63.     plr.Chatted:Connect(function(msg)
  64.         if string.lower(msg) == ";ff" then
  65.             Instance.new("ForceField", plr.Character)
  66.         end
  67.     end)
  68. end)
  69.  
  70. local Values = {
  71.     Wins = {
  72.         RagmasterWins = 5
  73.     }
  74. }
  75.  
  76. local PlayerData = ProfileStore.New("PlayerData", Values)
  77. local Profiles: {[player]: typeof(PlayerData:StartSessionAsync())} = {}
  78.  
  79. local function PlayerAdded(player: Player)
  80.  
  81.     local Id = tostring(player.UserId)
  82.  
  83.     local Profile = PlayerData:StartSessionAsync(Id, {
  84.         Cancel = function()
  85.             return player.Parent ~= Players
  86.         end,
  87.     })
  88.  
  89.     if Profile ~= nil then
  90.  
  91.         Profile:AddUserId(player.UserId)
  92.         Profile:Reconcile()
  93.  
  94.         Profile.OnSessionEnd:Connect(function()
  95.             Profile[player] = nil
  96.             player:Kick("Profile session end - please rejoin")
  97.         end)
  98.  
  99.         if player.Parent == Players then
  100.             Profiles[player] = Profile
  101.             print("Profile loaded for " .. player.Name)
  102.             print(Profile.Data)
  103.            
  104.             local fold = Instance.new("Folder", player)
  105.             fold.Name = "leaderstats"
  106.             local wins = Instance.new("IntValue", fold)
  107.             wins.Name = "Wins"
  108.            
  109.             for _, bosswins in Profile.Data.Wins do
  110.                 wins.Value += bosswins
  111.             end
  112.         else
  113.             Profile:EndSession()
  114.         end
  115.     else
  116.         player:Kick("Data load failed, please rejoin.")
  117.     end
  118. end
  119.  
  120. Players.PlayerAdded:Connect(PlayerAdded)
  121.  
  122. Players.PlayerRemoving:Connect(function(player)
  123.     local profile = Profiles[player]
  124.     if profile ~= nil then
  125.         profile:EndSession()
  126.     end
  127. end)
  128.  
  129. Events.BossBar.Event:Connect(function(gradient: UIGradient, char: Model)
  130.     if not char then return end
  131.     local bar = RS.BossBars.BossBar:Clone()
  132.     gradient:Clone().Parent = bar.BossBar
  133.    
  134.     for _, plr: Player in Players:GetPlayers() do
  135.        
  136.         local plrgui = plr:WaitForChild("PlayerGui")
  137.        
  138.         local BossBars = plrgui:WaitForChild("BossBars")
  139.        
  140.         if BossBars then
  141.             print("WOOOOWOOWOWH FOUND")
  142.             local barclone = bar:Clone()
  143.             barclone.Character.Value = char
  144.             barclone.LocalScript.Enabled = true
  145.             barclone.Parent = plr.PlayerGui.BossBars.BossBar
  146.         end
  147.     end
  148.    
  149.     local joinconnect = Players.PlayerAdded:Connect(function(plr: Player)
  150.        
  151.         local plrgui = plr:WaitForChild("PlayerGui")
  152.        
  153.         local BossBars = plrgui:WaitForChild("BossBars", 5)
  154.        
  155.         if BossBars then
  156.             local barclone = bar:Clone()
  157.             barclone.Character.Value = char
  158.             barclone.LocalScript.Enabled = true
  159.             barclone.Parent = plr.PlayerGui.BossBars.BossBar
  160.         end
  161.     end)
  162.    
  163.     char:FindFirstChildOfClass("Humanoid").Died:Once(function()
  164.         joinconnect:Disconnect()
  165.     end)
  166. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement