001 | Hint = Instance.new( "Hint" ) |
002 | Hint.Text = "Loading..." |
003 | Hint.Parent = workspace |
004 |
005 | Badges = { [ 0 ] = 30058718 , [ 100 ] = 29890585 , [ 200 ] = 29918752 , [ 400 ] = 30057939 } |
006 | Playing = { } |
008 | BallName = "bawlz" |
009 | Base = workspace.Base |
010 | CountDownTime = 20 |
011 | Siz = 8 |
012 | Size = Vector 3. new(Siz, Siz, Siz) |
013 | Multiplier = 1 |
014 | SuckSpeed = 1.5 |
015 | SuckSoundId = "http://www.roblox.com/asset/?id=10722059" |
016 | TickSoundId = "rbxasset://sounds\\clickfast.wav" |
017 | PingSoundId = "http://www.roblox.com/asset/?id=13114759" |
018 | HorrorSoundId = "http://www.roblox.com/asset/?id=2767085" |
019 | LostSoundId = "http://www.roblox.com/asset/?id=13378571" |
020 | WonSoundId = "http://www.roblox.com/asset/?id=15632562" |
021 | EatTime = 2 |
022 | BallMass = 15000 |
023 | copyrate = 12 |
024 | Powerups = { } |
025 | Lobby = script.Parent.Lobby |
026 |
027 |
028 | WavePoints = 200 |
029 | RawStages = game:GetService( "Lighting" ):GetChildren() |
030 | Stages = { } |
031 | for i, v in pairs (RawStages) do |
032 | if v:IsA( "Model" ) then |
033 | local c = math.random( 0 , 1 ) |
034 | if c = = 0 then |
035 | table.insert(Stages, 1 , v) |
036 | else |
037 | table.insert(Stages, v) |
038 | end |
039 | end |
040 | end |
041 | Index = math.random( 1 , #Stages) |
042 | TickSound = Instance.new( "Sound" ) |
043 | TickSound.Pitch = 2 |
044 | TickSound.Volume = 0.3 |
045 | TickSound.SoundId = TickSoundId |
046 | TickSound.Parent = workspace |
047 | PingSound = Instance.new( "Sound" ) |
048 | PingSound.Pitch = 0.7 |
049 | PingSound.Volume = 1 |
050 | PingSound.SoundId = PingSoundId |
051 | PingSound.Parent = workspace |
052 | HorrorSound = Instance.new( "Sound" ) |
053 | HorrorSound.Pitch = 1.5 |
054 | HorrorSound.Volume = 0.3 |
055 | HorrorSound.SoundId = HorrorSoundId |
056 | HorrorSound.Parent = workspace |
057 | LostSound = Instance.new( "Sound" ) |
058 | LostSound.Pitch = 0.5 |
059 | LostSound.Volume = 1 |
060 | LostSound.SoundId = LostSoundId |
061 | LostSound.Parent = workspace |
062 | WonSound = Instance.new( "Sound" ) |
063 | WonSound.Pitch = 1.2 |
064 | WonSound.Volume = 1 |
065 | WonSound.SoundId = WonSoundId |
066 | WonSound.Parent = workspace |
067 |
068 | function AwardBadge(Player, Badge) |
069 | spawn( function () game:GetService( "BadgeService" ):AwardBadge(Player.userId, Badge) end ) |
070 | end |
071 | function Talk(Text, Time) |
072 | Hint.Text = Text |
073 |
074 | wait(Time) |
075 | end |
076 | function GetStage() |
077 | Talk( "Choosing stage..." , 2 ) |
078 | local index = Index |
079 | local frames = 15 |
080 | for i = 1 , frames do |
081 | index = index + 1 |
082 | if index > #Stages then index = 1 end |
083 | TickSound:Play() |
084 | Talk( "Stage: " .. Stages [ index ] .Name, i/frames* 0.5 ) |
085 | end |
086 | Index = Index + 1 |
087 | if Index > #Stages then Index = 1 end |
088 | local Stage = Stages [ Index ] |
089 | Talk( "Stage: " .. Stage.Name, 0.6 ) |
090 | PingSound:Play() |
091 | Talk(Stage.Name .. " is selected!" , 5 ) |
092 | return Stage |
093 | end |
094 | function StartWave() |
095 | WaveTime = 60 |
096 | local pSurvivors = game:GetService( "Players" ):GetChildren() |
097 | local nPlayers = 0 |
098 | for Index, Survivor in pairs (pSurvivors) do |
099 | if Playing [ Survivor ] then |
100 | nPlayers = nPlayers + 1 |
101 | end |
102 | end |
103 | if nPlayers = = 0 then Talk( "No players? Then skip this round." , 4 ) return true end |
104 | Survivors = { } |
105 | for Index, Survivor in pairs (pSurvivors) do |
106 | if Playing [ Survivor ] then |
107 | pcall ( function () |
108 | Survivor.Character:MoveTo(Vector 3. new(math.random(- 90 , 90 ), 35 , math.random(- 90 , 90 ))) |
109 | while (Vector 3. new() - Survivor.Character.Humanoid.Torso.Position).magnitude < 50 do |
110 | Survivor.Character:MoveTo(Vector 3. new(math.random(- 90 , 90 ), 35 , math.random(- 90 , 90 ))) |
111 | end |
112 | Survivor.Character.Humanoid.Died:connect( function () Survivors [ Survivor ] = nil end ) |
113 | Survivors [ Survivor ] = true |
114 | WaveTime = WaveTime + 3.75 |
115 | end ) |
116 | end |
117 | end |
118 | WaveTime = math.floor(WaveTime) |
119 | Hungries = Instance.new( "Model" ) |
120 | Hungries.Name = "Hungries" |
121 | Hungries.Parent = workspace |
122 | Talk( "Starting game..." , 2 ) |
123 | HorrorSound:Play() |
124 | spawn( function () |
125 | Infections = { } |
126 | function GetClosestPart(c) |
127 | local t, dist = nil , 100000 |
128 | for _ in pairs (Survivors) do |
129 | local e |
130 | if pcall ( function () e = _.Character.Humanoid.Torso end ) then |
131 | if (c.Position - e.Position).magnitude < dist then |
132 | dist = (c.Position - e.Position).magnitude |
133 | t = e |
134 | end |
135 | end |
136 | end |
137 | return t, dist |
138 | end |
139 | function Eat(part, ir, s) |
140 | part.CanCollide = false |
141 | part.Anchored = true |
142 | while (part.Position - ir.Position).magnitude > Siz / 3 do |
143 | local c = { part.CFrame:components() } |
144 | local v = part.Position + CFrame.new(part.Position, ir.Position).lookVector * SuckSpeed |
145 | c [ 1 ] = v.X |
146 | c [ 2 ] = v.Y |
147 | c [ 3 ] = v.Z |
148 | part.CFrame = CFrame.new( unpack (c)) |
149 | wait() |
150 | end |
151 | s:Play() |
152 | part.Anchored = false |
153 | part:BreakJoints() |
154 | local p = Join(ir, part) |
155 | wait(EatTime) |
156 | if p.Parent then |
157 | Kill(part) |
158 | end |
159 | end |
160 | function Kill(part) |
161 | part:Remove() -- For now. |
162 | end |
163 | function Join(Part 0 , Part 1 ) |
164 | local Connector = Instance.new( "Weld" ) |
165 | Connector.C 0 = Part 0. CFrame:inverse() |
166 | Connector.C 1 = Part 1. CFrame:inverse() |
167 | Connector.Part 0 = Part 0 |
168 | Connector.Part 1 = Part 1 |
169 | Connector.Parent = Part 0 |
170 | return Connector |
171 | end |
172 | function MakeNew(pos) |
173 | local ttt = 0 |
174 | local i = Instance.new( "Part" ) |
175 | Infections [ i ] = true |
176 | i.BottomSurface = 0 |
177 | i.Color = Color 3. new( 215 , 215 , 0 ) |
178 | i.formFactor = 0 |
179 | i.Locked = true |
180 | i.Parent = Hungries |
181 | i.Position = pos |
182 | i.Shape = 0 |
183 | i.Size = Size |
184 | i.Transparency = 0.3 |
185 | i.TopSurface = 0 |
186 | local s = Instance.new( "Sound" ) |
187 | s.SoundId = SuckSoundId |
188 | s.Parent = i |
189 | i.Touched:connect( function (Hit) |
190 | if Hit:GetMass() < BallMass and not Infections [ Hit ] and not Hit:IsDescendantOf(Lobby) then |
191 | Infections [ Hit ] = true |
192 | Eat(Hit, i, s) |
193 | ttt = ttt + 1 |
194 | if ttt > copyrate then |
195 | ttt = 0 |
196 | for i = 1 , Multiplier do |
197 | MakeNew(Hit.Position) |
198 | end |
199 | end |
200 | end |
201 | end ) |
202 | local life = 40 |
203 | local v = Instance.new( "BodyAngularVelocity" ) |
204 | v.angularvelocity = Vector 3. new() |
205 | v.P = 3 |
206 | v.maxTorque = Vector 3. new( 1 e+ 15 , 1 e+ 15 , 1 e+ 15 ) |
207 | v.Parent = i |
208 | while true do |
209 | wait( 0.1 ) |
210 | if i.Position.X < - 95 or i.Position.X > 95 or i.Position.Y < 0 or i.Position.Y > 40 or i.Position.Z < - 95 or i.Position.Z > 95 then |
211 | i.Position = Vector 3. new() |
212 | end |
213 | if math.random( 1 , 50 ) = = 1 then |
214 | i.Velocity = i.Velocity + Vector 3. new( 0 , 50 , 0 ) |
215 | end |
216 | if i.Velocity.magnitude > 50 then |
217 | i.Velocity = i.Velocity.unit * 50 |
218 | end |
219 | local t, Dist = GetClosestPart(i) |
220 | if t then |
221 | t = t.Position - i.Position |
222 | local x = -t.z |
223 | local y = 0 |
224 | local z = t.x |
225 | v.angularvelocity = -Vector 3. new(x, y, z).unit * 40 * ((t.x^ 2 +t.z^ 2 )^ 0.5 /Dist/ 4 + 0.75 ) |
226 | end |
227 | life = life - 0.1 |
228 | if life < = 0 then |
229 | break |
230 | end |
231 | end |
232 | Kill(i, i) |
233 | end |
234 | MakeNew(Vector 3. new()) |
235 | end ) |
236 | for i = WaveTime, 0 , - 1 do |
237 | Talk(i .. " seconds till wave ends. Survive for points!" , 1 ) |
238 | local nSurvivors = 0 |
239 | for Survivor in pairs (Survivors) do |
240 | nSurvivors = nSurvivors + 1 |
241 | end |
242 | if nSurvivors = = 0 then |
243 | LostSound:Play() |
244 | Talk( "All players FAILED!" , 3 ) |
245 | break |
246 | end |
247 | if #Hungries:GetChildren() = = 0 then |
248 | WonSound:Play() |
249 | Talk( "All " .. BallName .. " died!" , 3 ) |
250 | break |
251 | end |
252 | end |
253 | end |
254 | function EndWave() |
255 | Infections = { } |
256 | Hungries:Remove() |
257 | PingSound:Play() |
258 | Talk( "Game over!" , 4 ) |
259 | local nSurvivors = 0 |
260 | for Survivor in pairs (Survivors) do |
261 | nSurvivors = nSurvivors + 1 |
262 | end |
263 | local Index = 1 |
264 | local sSurvivors = "" |
265 | for Survivor in pairs (Survivors) do |
266 | if Index > 1 then |
267 | if Index = = nSurvivors then |
268 | sSurvivors = sSurvivors .. " and " |
269 | else |
270 | sSurvivors = sSurvivors .. ", " |
271 | end |
272 | end |
273 | sSurvivors = sSurvivors .. Survivor.Name |
274 | Index = Index + 1 |
275 | end |
276 | if nSurvivors > 0 then |
277 | local Points = math.ceil(WavePoints / nSurvivors) |
278 | for Survivor in pairs (Survivors) do |
279 | pcall ( function () Survivor.leaderstats.Points.Value = Survivor.leaderstats.Points.Value + Points end ) |
280 | pcall ( function () Survivor.Character:BreakJoints() end ) |
281 | pcall ( function () for Index, Value in pairs (Badges) do if Survivor.leaderstats.Points.Value > = Index then AwardBadge(Survivor, Value) end end end ) |
282 | end |
283 | Talk(sSurvivors .. " survived and got " .. Points .. " points." , 4 ) |
284 | else |
285 | Talk( "Everybody died. No points for this round." , 4 ) |
286 | end |
287 | end |
288 | function CountDown() |
289 | for i = CountDownTime, 0 , - 1 do |
290 | Talk( "New game starting in " .. i .. " seconds." , 1 ) |
291 | end |
292 | end |
293 | function GetMass(Object, Mass) |
294 | Mass = Mass or 0 |
295 | if Object:IsA( "BasePart" ) then Mass = Mass + Object:GetMass() end |
296 | for Index, Value in pairs (Object:GetChildren()) do |
297 | Mass = GetMass(Value, Mass) |
298 | end |
299 | return Mass |
300 | end |
301 | function UpdatePowerUps(Player) |
302 | pcall ( function () Player.Character.Humanoid.WalkSpeed = Powerups [ Player ] .WalkSpeed end ) |
303 | pcall ( function () |
304 | local Torso = Player.Character.Humanoid.Torso |
305 | local AntiGrav = Torso:FindFirstChild( "BodyForce" ) or Instance.new( "BodyForce" ) |
306 | AntiGrav.force = Vector 3. new( 0 , GetMass(Player.Character) * 196.2 * Powerups [ Player ] .AntiGrav / 100 , 0 ) |
307 | AntiGrav.Parent = Torso |
308 | end ) |
309 | end |
310 | function PlayerJoined(Player) |
311 | local Stats = Instance.new( "IntValue" ) |
312 | Stats.Name = "leaderstats" |
313 | Stats.Parent = Player |
314 | local Points = Instance.new( "IntValue" ) |
315 | Points.Name = "Points" |
316 | Points.Value = 0 |
317 | Points.Parent = Stats |
318 |
319 | end |
320 | function PlayerLeft(Player) |
321 | pcall ( function () Survivors [ Player ] = nil end ) |
322 | end |
323 | game:GetService( "Players" ).PlayerAdded:connect(PlayerJoined) |
324 | game:GetService( "Players" ).PlayerRemoving:connect(PlayerLeft) |
325 |
326 | while true do |
327 | if game:GetService( "Players" ).NumPlayers > 0 then |
328 | CountDown() |
329 | local Stage = GetStage():Clone() |
330 | if Stage:FindFirstChild( "BaseColor" ) then |
331 | Base.BrickColor = Stage.BaseColor.Value |
332 | else |
333 | Base.BrickColor = BrickColor.new( "Camo" ) |
334 | end |
335 | Stage.Parent = workspace |
336 | Stage:MakeJoints() |
337 | Base:MakeJoints() |
338 | for Index, Object in pairs (Stage:GetChildren()) do if Object:IsA( "BasePart" ) then Object.Velocity = Vector 3. new() Object.RotVelocity = Vector 3. new() end end |
339 | local b = StartWave() |
340 | Stage:Remove() |
341 | if not b then |
342 | EndWave() |
343 | end |
344 | Base.BrickColor = BrickColor.new( "Navy blue" ) |
345 | else |
346 | wait() |
347 | end |
348 | end |