-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArena Game (LMS)
258 lines (188 loc) · 5.7 KB
/
Arena Game (LMS)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
-- ARENA (Last Man Standing)
-->
--> Build Lobby
--> ServerStorage -> add Folder "Maps" --> Build Arena as Model "[Customname]map"
--> ServerStorage -> add tool "Sword"
--> ReplicatedStorage -> add StringValue "Status"
--> StarterGUI -> add ScreenGUI "Status" -> Add TextLabel Pos [0.5,-250][0,50] Size [0,500][0,50], TextScaled, ZIndex=2 -> add LocalScript
local Status = game:GetService("ReplicatedStorage"):WaitForChild("Status")
script.Parent.Text = Status.Value
Status:GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Text = Status.Value
end)
--> ServerScriptStorage --> Add Script "Stats"
local dataStores = game:getService("DataStoreService"):GetDataStore("BucksDataStore")
local defaultCash = 0
local defaultWin =0
local playersLeft = 0
game.Players.PlayerAdded:Connect(function(player)
playersLeft = playersLeft + 1
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local bucks = Instance.new("IntValue")
bucks.Name = "Bucks"
bucks.Value = 0
bucks.parent = leaderstats
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = 0
wins.parent = leaderstats
player.CharacterAdded:Connect(function(character)
character.Humanoid.WalkSpeed = 16
character.Humanoid.Died:Connect(function()
if character.humanoid and character.Humanoid:FindFirstChild("creator") then
game.ReplicatedStorage.Status.Value = tostring(character.Humanoid.creator.Value).." KILLED "..player.Name
end
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
player:LoadCharacter()
end
end)
-- Data Stores
local player_data
pcall(function()
player_data = dataStores:GetAsync(player.UserID.."-Bucks")
player_data = dataStores:GetAsync(player.UserID.."-Wins")
end)
if player_data ~= nil than
bucks.Value = player_dataat
wins.Value = player_data
else
bucks.Value = defaultCash
wins.Value = defaultWin
end
end)
local bindableEvent = Instance.new("BindableEvent")
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
DataStores:SetAsync(player.UserID.."-Bucks",player.leaderstats.Bucks.Value )
DataStores:SetAsync(player.UserID.."-Wins",player.leaderstats.Wins.Value )
playersLeft = playersLeft - 1
bindableEvent:Fire()
end)
end)
game:BindToClose(function()
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
end)
--> ServerScriptStorage --> Add Script "Main"
--Variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local MapsFolder = ServerStorage:WaitForChild("Maps")
local Status = ReplicatedStorage:WaitForChild("Status")
local GameLength = 60
local reward = 25
local starting = 15
-- Game Loop
while true do
Status.Value = "Waiting for Players"
repeat wait(1) until game.Players.NumPlayers >= 2
for i = starting, 0, -1 do
Status.Value = "New Round in "..i.." Seconds"
wait(1)
end
local plrs = {}
for i, player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player) -- Add each player into plrs table
end
end
wait(2)
local AvailableMaps = MapsFolder:GetChildren()
local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)
Status.Value = ChosenMap.Name.." chosen and "..#plrs.." players in game"
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = workspace
wait(1)
-- Teleport Player to Maps
local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
if not SpawnPoints then
print("Spawnpoints not found!")
end
local AvailableSpawnPoints = SpawnPoints:GetChildren()
for i, player in pairs(plrs) do
if i > 6 then --test
table.remove(plrs,i) --test
end --test
if player then
character = player.Character
if character then
character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
table.remove(AvailableSpawnPoints,1)
local Sword = ServerStorage.Sword(clone()
Sword.Parent = player.Backpack()
local GameTag = Instance.new("BoolValue")
GameTag.Name ="GameTag"
GameTag.Parent = player.Character
else
if not player then
table.remove(plrs,i)
end
end
end
end
Status.Value = "Prepare yourselves!"
wait(2)
for i = GameLength, 0, -1 do
for x, Player in pairs(plrs) do
if player then
character = player.Character
if not character then
table.remove(plrs,x)
else
if character:FindFirstChild("GameTag") then
print(player.Name.." is still in the game")
else
table.remove(plrs,x)
print(player.Name.." has been removed"
end
end
else
table.remove(plrs,x)
print(player.Name.." has been removed"
end
end
Status.Value = "There are "..i.." Seconds remaining and "..#plrs.." players in game"
if #plrs == 1 then
Status.Value = "VICTORY: "..plrs[1].Name
plrs[1].leaderstats.Bucks.Value = plrs[1].leaderstats.Bucks.Value + reward
plrs[1].leaderstats.Wins.Value = plrs[1].leaderstats.Wins.Value + 1
break
elseif #plrs == 0 then
Status.Value = "DRAW!"
break
elseif
Status.Value = "Time's Up!"
break
end
wait(1)
end
print ("End of the Game")
wait(2)
for i, player in pairs(game.Players:GetPlayers()) do
character = player.Character
if not character then
--ignore
else
if character:FindFirstChild("GameTag") then
character.GameTag:Destroy()
end
if player.Backpack:FindFirstChild("Sword") then
player.Backpack.Sword:Destroy()
end
if character:FindFirstChild("Sword") then
character.Sword:Destroy()
end
end
player:LoadCharacter()
end
ClonedMap:Destroy()
Status.Value = "GAME OVER!"
wait(10)
Status.Value = "Next Game in 15 Seconds"
wait(15)
end