Advertisement
Guest User

Untitled

a guest
May 22nd, 2020
46,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.17 KB | None | 0 0
  1. local Player = script.Parent.Parent.Parent
  2. local Content = script.Parent.MainFrame.ScrollingFrame.Content
  3. local Characters = game.ReplicatedStorage.Characters
  4. local SetSubject = Characters.Parent.SetSubject
  5.  
  6. for index,item in pairs(Characters:GetChildren()) do
  7.     if item:FindFirstChild("Humanoid") then
  8.         local ViewportFrame = Instance.new("ViewportFrame")
  9.         ViewportFrame.Parent = Content
  10.         ViewportFrame.BackgroundTransparency = 1
  11.        
  12.         local Button = Instance.new("TextButton")
  13.         Button.Parent = ViewportFrame
  14.         Button.Position = UDim2.new(0,0,1,0)
  15.         Button.Size = UDim2.new(1,0,0,15)
  16.         Button.BorderSizePixel = 0
  17.         Button.BackgroundColor3 = Color3.fromRGB(255,255,255)
  18.         Button.Text = "Spawn"
  19.         Button.TextScaled = true
  20.        
  21.         local Preview = item:Clone()
  22.         Preview.Parent = ViewportFrame
  23.        
  24.         local Camera = Instance.new("Camera")
  25.         Camera.Parent = ViewportFrame
  26.         Camera.CFrame = Preview.Head.CFrame + Preview.Head.CFrame.LookVector * 5
  27.         Camera.CFrame = CFrame.new(Camera.CFrame.Position,Preview.Head.Position)
  28.        
  29.         ViewportFrame.CurrentCamera = Camera
  30.        
  31.         Button.MouseButton1Down:Connect(function()
  32.             script.Parent.Enabled = false
  33.             local ChosenCharacter = item:Clone()
  34.             local CurrentCharacter = Player.Character
  35.             local LocalScripts = {}
  36.            
  37.             for index2,item2 in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
  38.                 if item2:IsA('LocalScript') then
  39.                     table.insert(LocalScripts,item2:Clone())
  40.                 else
  41.                     item2:Clone().Parent = ChosenCharacter
  42.                 end
  43.             end
  44.            
  45.             CurrentCharacter.Health:Clone().Parent = ChosenCharacter
  46.             table.insert(LocalScripts,CurrentCharacter.Animate:Clone())    
  47.             ChosenCharacter.Parent = workspace
  48.             Player.Character = ChosenCharacter
  49.             for index2,item2 in pairs(LocalScripts) do
  50.                 item2.Parent = ChosenCharacter
  51.             end
  52.             SetSubject:FireClient(Player,ChosenCharacter.Humanoid)
  53.            
  54.             local Connection
  55.            
  56.             local function onDied()
  57.                 wait(game.Players.RespawnTime)
  58.                 Player:LoadCharacter()
  59.                 script.Parent.Enabled = true
  60.                 if Connection then
  61.                     Connection:Disconnect()
  62.                 end
  63.             end
  64.            
  65.             Connection = ChosenCharacter.Humanoid.Died:Connect(onDied)
  66.            
  67.         end)
  68.        
  69.     end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement