-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.luau
More file actions
166 lines (115 loc) · 3.47 KB
/
code.luau
File metadata and controls
166 lines (115 loc) · 3.47 KB
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
--Defining variables
local ReplicatedStorage=game:GetService("ReplicatedStorage")
local ServerStorage=game:GetService("ServerStorage")
local MapsFolder=ServerStorage:WaitForChild("Maps")
local Status=ReplicatedStorage:WaitForChild("Status")
local GameLength=100
local reward=100
--Game loop
while true do
Status.Value="Waiting for 2 or more players😅..."
repeat wait(1) until game.Players.NumPlayers >=2
Status.Value="Intermission(wait for match😅)"
wait(10)
local plrs={}
--For loop to insert players into plrs table
for i,player in pairs(game.Players:GetPlayers()) do
if player then
table.insert(plrs,player) --Adding each player into the game
end
end
wait(2)
local AvailableMaps=MapsFolder:GetChildren()
local ChosenMap=AvailableMaps[math.random(1,#AvailableMaps)]
Status.Value=ChosenMap.Name.." map is chosen to fight!"
local ClonedMap=ChosenMap:Clone()
ClonedMap.Parent=game.workspace
--Teleport players to the map
local SpawnPoints=ClonedMap:FindFirstChild("SpawnPoints")
if not SpawnPoints then
print("Error: SpawnPoints in "..ClonedMap.Name.." not found.")
end
local AvailableSpawnPoints=SpawnPoints:GetChildren()
for i,player in pairs(plrs) do
if player then
character=player.Character
if character then
--Code to teleport character
character:FindFirstChild("HumanoidRootPart").CFrame=AvailableSpawnPoints[1].CFrame
table.remove(AvailableSpawnPoints,1)
--Give players a sword to fight(duh)
local Sword=ServerStorage:WaitForChild("Sword"):Clone()
Sword.Parent=player.Backpack
local GameTag=Instance.new("BoolValue")
GameTag.Name="GameTag"
GameTag.Parent=player.Character
else
--There is no character
if not player then
table.remove(plrs,i)
end
end
end
end
Status.Value="Fight!"
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
--Left the game
else
if character:FindFirstChild("GameTag") then
-- They are still fighting for their LIVES ⚔️
print(player.Name.." is still alive!")
else
-- They are DEAD😵
table.remove(plrs,x)
print(player.Name.." has died.!")
end
end
else
table.remove(plrs,x)
print(player.Name.." has been removed.!")
end
end
Status.Value="The are "..i.." seconds and "..#plrs.." players remaining!"
if #plrs==1 then
-- Someone won
local leaderstats=plrs[1] and plrs[1]:FindFirstChild("leaderstats")
local coinStat=leaderstats and leaderstats:FindFirstChild("Coins")
coinStat.Value+=reward
Status.Value=plrs[1].Name.." has won!"
break
elseif #plrs==0 then
Status.Value="Did two players kill each other at the same time? Because nobody won!"
break
elseif i==0 then
Status.Value="Sorry! Time up!☹"
break
end
wait(1)
end
print("End of game!")
for i,player in pairs(game.Players:GetPlayers())do
character=player.Character
if not character then
--Ignore them because they might have left
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
player:LoadCharacter()
end
end
ClonedMap:Destroy()
wait(2)
Status.Value="Battle fininshed!"
end