Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. --Services
  2. local rep = game:GetService("ReplicatedStorage")
  3. local plrs = game:GetService("Players")
  4.  
  5. --Variables -- Defines where a place is easier
  6. local kspawn = workspace:WaitForChild("KillerSpawn")
  7. local sspawn = workspace:WaitForChild("SurvivorSpawns")
  8. local request
  9. local gametime = 500 -- How long the game will last
  10. local waitingtime = 5 -- How long the game takes before starting
  11.  
  12. --Tables
  13. local playersInMatch = {}
  14. local playersInLobby = {}
  15.  
  16. --Remotes
  17. local remotes = game.ReplicatedStorage:WaitForChild("Remotes")
  18. local countdown = remotes:WaitForChild("CountDown")
  19.  
  20. local DEBUG = true
  21.  
  22. function debugPrint(text)
  23. if DEBUG then
  24. print("DEBUG: "..text)
  25. end
  26. end
  27.  
  28. --plr
  29. game.Players.PlayerAdded:Connect(function(plr)
  30. debugPrint(plr.." connected.")
  31. table.insert(playersInLobby, plr.Name)--adds player to lobby table
  32. local inGame = Instance.new("BoolValue", plr)--Creates bool value so we can know if they are inmatch or inlobby
  33. plr.CharacterAdded:Wait()--Waits for character to load
  34. plr.Character.Humanoid.Died:Connect(function()
  35. debugPrint(plr.." died.")
  36. if plr.inGame.Value == true then
  37. inGame.Value = false
  38. for i,v in pairs(playersInMatch) do
  39. if v == plr.Name then
  40. wait()
  41. table.remove(playersInMatch, plr.Name)
  42. end
  43. table.insert(playersInLobby, plr.Name)
  44. end
  45. end
  46. end)
  47. while wait(0.1) do
  48. if(#playersInMatch == 0) then
  49. request = "StartCountDown"
  50. for Num = waitingtime, 0-1 do
  51. countdown:FireAllClients(request, Num)
  52. end
  53. end
  54. end
  55. end)
  56.  
  57.  
  58.  
  59. --Functions
  60. function FindIndex(Table,Val)
  61. for index,v in pairs(Table) do
  62. if v == Val then
  63. return index
  64. end
  65. end
  66. end
  67.  
  68.  
  69. --Main
  70. while wait() do
  71. if#plrs:GetPlayers() >= 2 then
  72. request = "StartCountDown"
  73. for Num = waitingtime, 0,-1 do
  74. countdown:FireAllClients(request,Num)
  75. wait(1)
  76. end
  77.  
  78. local allplayers = {}
  79. for i,plr in pairs(plrs:GetPlayers()) do
  80. table.insert(allplayers,plr)
  81. end
  82.  
  83. local killer = allplayers[math.random(#allplayers)]
  84. table.remove(allplayers,FindIndex(allplayers,killer))
  85.  
  86. --Teleport
  87. killer.Character:SetPrimaryPartCFrame(kspawn.Spawn.CFrame + Vector3.new(0,3,0))
  88. local knife = game.ReplicatedStorage:WaitForChild("Knife"):Clone()
  89. knife.Parent = killer.Backpack
  90. killer.Character.Humanoid.WalkSpeed = 6
  91.  
  92. for i,plr in pairs(allplayers) do
  93. debugPrint(plr.Name.." has spawned.")
  94. table.insert(playersInMatch, plr.Name)
  95. table.remove(playersInLobby, plr.Name)
  96. plr.InGame.Value = true
  97. local char = plr.Character or plr.CharacterAdded:Wait()
  98. local number = math.random(1,9)
  99. local oof = sspawn:FindFirstChild("Spawn"..number)
  100. char.HumanoidRootPart.CFrame = oof.CFrame + Vector3.new(0,3,0)
  101. char.Humanoid.WalkSpeed = 5.8
  102. end
  103.  
  104. request = "CountDown"
  105. for Num = gametime,0,-1 do
  106. countdown:FireAllClients(request,Num)
  107. wait(1)
  108. end
  109. for i,plr in pairs(allplayers) do
  110. debugPrint("Resetting "..plr.Name..".")
  111. plr.Character.Humanoid.Health = 0
  112. killer.Character.Humanoid.Health = 0
  113. end
  114. end
  115. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement