Advertisement
MasterRecorder

Scripts

Jun 27th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. stats script in serverscriptservice:
  2.  
  3. local dataStores = game:GetService("DataStoreService"):GetDataStore("CashDataStore")
  4. local defaultCash = 10
  5. local playersLeft = 0
  6.  
  7. game.Players.PlayerAdded:Connect(function(player)
  8.  
  9. playersLeft = playersLeft + 1
  10.  
  11. local leaderstats = Instance.new("Folder")
  12. leaderstats.Name = "leaderstats"
  13. leaderstats.Parent = player
  14.  
  15. local cash = Instance.new("IntValue")
  16. cash.Name = "Cash"
  17. cash.Value = 0
  18. cash.Parent = leaderstats
  19.  
  20.  
  21. player.CharacterAdded:Connect(function(character)
  22. character.Humanoid.WalkSpeed = 16
  23. character.Humanoid.Died:Connect(function()
  24. -- Whenever somebody dies the event will run
  25.  
  26. if character.Humanoid and character.Humanoid:FindFirstChild("creator") then
  27. game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." KILLED "..player.Name
  28. end
  29.  
  30. if character:FindFirstChild("GameTag") then
  31. character.GameTag:Destroy()
  32. end
  33.  
  34. player:LoadCharacter()
  35. end)
  36.  
  37. end)
  38.  
  39. -- Data Stores
  40.  
  41. local player_data
  42.  
  43. pcall(function()
  44. player_data = dataStores:GetAsync(player.UserId.."-Cash") --1736284-Cash
  45. end)
  46.  
  47. if player_data ~= nil then
  48. -- Player has saved data , load it in
  49. cash.Value = player_data
  50. else
  51. -- New player
  52. cash.Value = defaultCash
  53. end
  54.  
  55. end)
  56.  
  57. local bindableEvent = Instance.new("BindableEvent")
  58.  
  59. game.Players.PlayerRemoving:Connect(function(player)
  60.  
  61. pcall(function()
  62. dataStores:SetAsync(player.UserId.."-Cash",player.leaderstats.Cash.Value)
  63. print("Saved")
  64. playersLeft = playersLeft - 1
  65. bindableEvent:Fire()
  66. end)
  67.  
  68. end)
  69.  
  70. game:BindToClose(function()
  71. -- This will be triggered upon shutdown
  72. while playersLeft > 0 do
  73. bindableEvent.Event:Wait()
  74. end
  75. end)
  76.  
  77. -----------------------------------------
  78. MainScript in ServerScriptService:
  79.  
  80. -- Define variables
  81.  
  82. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  83.  
  84. local ServerStorage = game:GetService("ServerStorage")
  85.  
  86. local MapsFolder = ServerStorage:WaitForChild("Maps")
  87.  
  88. local Status = ReplicatedStorage:WaitForChild("Status")
  89.  
  90. local GameLength = 50
  91.  
  92. local reward = 100
  93.  
  94. -- Game loop
  95.  
  96. while true do
  97.  
  98. Status.Value = "Waiting for enough players"
  99.  
  100. repeat wait(1) until game.Players.NumPlayers >= 2
  101.  
  102. Status.Value = "Intermission"
  103.  
  104. wait(10)
  105.  
  106. local plrs = {}
  107.  
  108. for i, player in pairs(game.Players:GetPlayers()) do
  109. if player then
  110. table.insert(plrs,player) -- Add each player into plrs table
  111. end
  112. end
  113.  
  114. wait(2)
  115.  
  116. local AvailableMaps = MapsFolder:GetChildren()
  117.  
  118. local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
  119.  
  120. Status.Value = ChosenMap.Name.." Chosen"
  121.  
  122. local ClonedMap = ChosenMap:Clone()
  123. ClonedMap.Parent = workspace
  124.  
  125. -- Teleport players to the map
  126.  
  127. local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
  128.  
  129. if not SpawnPoints then
  130. print("SpawnPoints Not Found!")
  131. end
  132.  
  133. local AvailableSpawnPoints = SpawnPoints:GetChildren()
  134.  
  135. for i, player in pairs(plrs) do
  136. if player then
  137. character = player.Character
  138.  
  139. if character then
  140. -- Teleport Them
  141.  
  142. character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
  143. table.remove(AvailableSpawnPoints,1)
  144.  
  145.  
  146. -- Give them a sword
  147.  
  148. local Sword = ServerStorage.Sword:Clone()
  149. Sword.Parent = player.Backpack
  150.  
  151. local GameTag = Instance.new("BoolValue")
  152. GameTag.Name = "GameTag"
  153. GameTag.Parent = player.Character
  154.  
  155. else
  156. -- There is no character
  157. if not player then
  158. table.remove(plrs,i)
  159. end
  160. end
  161. end
  162. end
  163.  
  164.  
  165. Status.Value = "Get Ready To Play!"
  166.  
  167. wait(2)
  168.  
  169. for i = GameLength,0,-1 do
  170.  
  171. for x, player in pairs(plrs) do
  172. if player then
  173.  
  174. character = player.Character
  175.  
  176. if not character then
  177. -- Left the game
  178. table.remove(plrs,x)
  179. else
  180. if character:FindFirstChild("GameTag") then
  181. -- They are still alive
  182. print(player.Name.."is still in the game")
  183. else
  184. -- They are dead
  185. table.remove(plrs,x)
  186. print(player.Name.." has been removed!")
  187. end
  188. end
  189. else
  190. table.remove(plrs,x)
  191. print(player.Name.." has been removed!")
  192. end
  193. end
  194.  
  195. Status.Value = "There are "..i.." seconds remaining, and "..#plrs.." players left"
  196.  
  197. if #plrs == 1 then
  198. -- Last person standing
  199. Status.Value = "The winner is "..plrs[1].Name
  200. plrs[1].leaderstats.Cash.Value = plrs[1].leaderstats.Cash.Value + reward
  201. break
  202. elseif #plrs == 0 then
  203. Status.Value = "Nobody won!"
  204. break
  205. elseif i == 0 then
  206. Status.Value = "Time up!"
  207. break
  208. end
  209.  
  210. wait(1)
  211. end
  212.  
  213. print("End Of Game")
  214.  
  215. wait(2)
  216.  
  217. for i, player in pairs(game.Players:GetPlayers()) do
  218. character = player.Character
  219.  
  220. if not character then
  221. -- Ignore them
  222. else
  223. if character:FindFirstChild("GameTage") then
  224. character.GameTag:Destroy()
  225. end
  226.  
  227. if player.Backpack:FindFirstChild("Sword") then
  228. player.Backpack.Sword:Destroy()
  229. end
  230.  
  231. if character:FindFirstChild("Sword") then
  232. character.Sword:Destroy()
  233. end
  234.  
  235. end
  236.  
  237. player:LoadCharacter()
  238. end
  239.  
  240. ClonedMap:Destroy()
  241.  
  242. Status.Value = "Game ended"
  243.  
  244. wait(2)
  245. end
  246.  
  247. localscript in textlabel:
  248.  
  249. local Status = game:GetService("ReplicatedStorage"):WaitForChild("Status")
  250.  
  251. script.Parent.Text = Status.Value
  252.  
  253. Status:GetPropertyChangedSignal("Value"):Connect(function()
  254.  
  255. script.Parent.Text = Status.Value
  256.  
  257. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement