local roundtime = 60 * 5
local intermissiontime = 20
local marketservice = game:GetService("MarketplaceService")
local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerData")
local serverstorage = game:GetService("ServerStorage")
local replicatedstorage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")
local event = replicatedstorage:WaitForChild("RemoteEvent")
local maps = serverstorage:WaitForChild("Maps")
local mapholder = game.Workspace:WaitForChild("MapHolder")
local statustag = replicatedstorage:WaitForChild("StatusTag")
local timertag = replicatedstorage:WaitForChild("TimerTag")
local playerdata = {}
-- Set up score leaderboard
-- Keep track of points
-- Drop sheriff net gun if bloxxed
-- Make sure sheriff doesn't blox bystanders
function awardwin(player)
if player then
local mydata = playerdata[player.userId]
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats and mydata then
mydata.wins = mydata.wins + 1
local winsvalue = leaderstats:FindFirstChild("Wins")
if winsvalue then
winsvalue.Value = mydata.wins
end
end
end
end
function awardpoints(player, points)
if player and points then
local mydata = playerdata[player.userId]
if mydata then
mydata.points = mydata.points + points
local pointsvalue = player:FindFirstChild("Points")
if pointsvalue then
pointsvalue.Value = mydata.points
end
end
end
end
function dropnetgun(pos)
local pickup = serverstorage:WaitForChild("Net Gun"):WaitForChild("Handle"):clone()
pickup.Name = "Pickup"
pickup.Anchored = true
pickup.CanCollide = false
pickup.CFrame = CFrame.new(pos)
local sparkles = Instance.new("Sparkles")
sparkles.SparkleColor = Color3.new(0, .5, 1)
sparkles.Parent = pickup
local given = false
pickup.Touched:connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player ~= bloxxer then
local backpack = player:FindFirstChild("Backpack")
if backpack and not given then
given = true
pickup:remove()
local netgun = serverstorage:WaitForChild("Net Gun"):clone()
netgun.Parent = backpack
sheriff = player
end
end
end
end)
for _, player in pairs(game.Players:GetChildren()) do
if player and player.Character and player.Character.Parent then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid and humanoid.WalkSpeed < 16 then
humanoid.WalkSpeed = 16
end
end
end
debris:AddItem(pickup,roundtime)
pickup.Parent=game.Workspace
end
function newcharacter(bloxxedplayer, character)
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Died:connect(function()
if bloxxedplayer == sheriff then
humanoid:UnequipTools()
local backpack = bloxxedplayer:FindFirstChild("Backpack")
if backpack then
backpack:ClearAllChildren()
end
local torso = character:FindFirstChild("Torso")
if torso then
dropnetgun(torso.Position)
end
end
local tag = humanoid:FindFirstChild("creator")
if tag and tag.Value and tag.Value.Parent == game.Players then
if tag.Value ~= bloxxer and bloxxedplayer ~= bloxxer then
local wrongdoer = tag.Value
if wrongdoer.Character and wrongdoer.Character.Parent then
local wrongdoerhumanoid = wrongdoer.Character:FindFirstChild("Humanoid")
if wrongdoerhumanoid then
wrongdoerhumanoid.Health = 0
end
end
end
end
end)
end
end
function playeradded(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
local mydata = datastore:GetAsync(player.userId) or {}
mydata.points = mydata.points or 0
mydata.wins = mydata.wins or 0
mydata.multiplier = mydata.multiplier or 1
mydata.emeraldsword = mydata.emeraldsword or 0
playerdata[player.userId] = mydata
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = mydata.wins
wins.Parent = leaderstats
local points = Instance.new("IntValue")
points.Name = "Points"
points.Value = mydata.points
points.Parent = player
local multiplier = Instance.new("IntValue")
multiplier.Name = "Multiplier"
multiplier.Value = mydata.multiplier
multiplier.Parent = player
local emeraldsword = Instance.new("IntValue")
emeraldsword.Name = "EmeraldSword"
emeraldsword.Value = mydata.emeraldsword
emeraldsword.Parent = player
local haste = Instance.new("IntValue")
haste.Name = "HasHaste"
haste.Value = mydata.hashaste
haste.Parent = player
leaderstats.Parent = player
player.CharacterAdded:connect(function(character)
newcharacter(player, character)
end)
if player.Character and player.Character.Parent then
newcharacter(player, player.Character)
end
end
game.Players.PlayerAdded:connect(playeradded)
for _, player in pairs(game.Players:GetPlayers()) do
playeradded(player)
end
function permanentsave(player)
if player then
local mydata = playerdata[player.userId]
if mydata then
datastore:SetAsync(player.userId, mydata)
end
end
end
game.Players.PlayerRemoving:connect(function(player)
if player then
permanentsave(player)
playerdata[player.userId] = nil
end
end)
game.OnClose = function()
for i, v in pairs(playerdata) do
datastore:SetAsync(i, v)
end
end
function findplayerbyid(userid)
for _, player in pairs(game.Players:GetPlayers()) do
if player and player.userId == userid then
return player
end
end
end
function productpurchased(userid,productid,ispurchased,isapppurchase)
if ispurchased then
local player = findplayerbyid(userid)
if player then
if productid == 1169828694 then
awardpoints(player,100)
end
end
end
end
marketservice.PromptProductPurchaseFinished:connect(productpurchased)
event.OnServerEvent:connect(function(player, ...)
if player then
local tuple = {...}
if tuple[1] == "Buy" then
if tuple[2] == "100Points" then
marketservice:PromptProductPurchase(player,1169828694,false,Enum.CurrencyType.Robux)
elseif tuple[2] == "BloxxerChance" then
local mydata = playerdata[player.userId]
if mydata and mydata.points >= 25 then
mydata.multiplier = mydata.multiplier + 5
if mydata.multiplier == 6 then
mydata.multiplier = 5
end
awardpoints(player, -25)
local multipliervalue = player:FindFirstChild("Multiplier")
if multipliervalue then
multipliervalue.Value = mydata.multiplier
end
end
elseif tuple[2] == "EmeraldSword" then
local mydata = playerdata[player.userId]
if mydata and mydata.points >= 100 and mydata.emeraldsword == 0 then
mydata.emeraldsword = 1
awardpoints(player, -100)
local emeraldswordvalue = player:FindFirstChild("EmeraldSword")
if emeraldswordvalue then
emeraldswordvalue.Value = mydata.emeraldsword
end
end
elseif tuple[2] == "Haste" then
local mydata = playerdata[player.userId]
print(mydata.hashaste)
print(mydata.points)
print(tuple[2])
if mydata and mydata.points >= 250 and mydata.hashaste == 0 then
mydata.hashaste = 1
print(mydata.hashaste)
print(mydata.points)
print(tuple[2])
awardpoints(player, -250)
local hashastevalue = player:FindFirstChild("HasHaste")
if hashastevalue then
hashastevalue.Value = mydata.hashaste
end
end
end
end
end
end)
while true do
-- Load a random map
statustag.Value = "Loading Map"
timertag.Value = -1
mapholder:ClearAllChildren()
wait(2)
local allmaps = maps:GetChildren()
local newmap = allmaps[math.random(1, #allmaps)]:clone()
newmap.Parent = mapholder
wait(2)
-- Wait for contestants
while true do
wait(5)
contestants = {}
for _, player in pairs(game.Players:GetPlayers()) do
if player and player.Character then
local humanoid = player.Character:WaitForChild("Humanoid")
if humanoid and humanoid.Health > 0 then
table.insert(contestants, player)
end
end
end
if #contestants >= 2 then
break
else
statustag.Value = "Waiting for Players"
timertag.Value = -1
end
end
statustag.Value = "Match"
timertag.Value = roundtime
-- Choose bloxxer
local weightedcontestants = {}
for _, player in pairs(contestants) do
if player then
local weight = 1
local mydata = playerdata[player.userId]
if mydata and mydata.multiplier then
weight = mydata.multiplier
end
for i = 1, weight do
table.insert(weightedcontestants, player)
end
end
end
bloxxer = weightedcontestants[math.random(1, #weightedcontestants)]
local mydata = playerdata[bloxxer.userId]
if mydata and mydata.multiplier and mydata.multiplier > 1 then
mydata.multiplier = 1
local multipliervalue = bloxxer:FindFirstChild("Multiplier")
if multipliervalue then
multipliervalue.Value = mydata.multiplier
end
end
-- Choose sheriff
while true do
randomplayer = contestants[math.random(1, #contestants)]
if randomplayer ~= bloxxer then
sheriff = randomplayer
break
end
end
-- Teleport contestants
local spawnsmodel = newmap:WaitForChild("Spawns")
local spawns = spawnsmodel:GetChildren()
for _, player in pairs(contestants) do
if player and player.Character and #spawns > 0 then
local torso = player.Character:WaitForChild("Torso")
local humanoid = player.Character:WaitForChild("Humanoid")
local spawnindex = math.random(1, #spawns)
local spawn = spawns[spawnindex]
if spawn and torso and humanoid then
humanoid.Health = 100
humanoid.WalkSpeed = 16
table.remove(spawns, spawnindex)
torso.CFrame = CFrame.new(spawn.Position + Vector3.new(0, 3, 0))
local matchtag = Instance.new("StringValue")
matchtag.Name = "MatchTag"
matchtag.Parent = player.Character
local backpack = player:FindFirstChild("Backpack")
if backpack then
if player == bloxxer then
local sword = serverstorage:WaitForChild("Sword"):clone()
sword.Parent = backpack
event:FireClient(player, "Class", "Bloxxer")
local mydata = playerdata[player.userId]
if mydata and mydata.emeraldsword == 1 then
local emeraldswordvalue = sword:FindFirstChild("EmeraldSword")
if emeraldswordvalue then
emeraldswordvalue.Value = true
end
end
elseif player == sheriff then
local netgun = serverstorage:WaitForChild("Net Gun"):clone()
netgun.Parent = backpack
event:FireClient(player, "Class", "Sheriff")
else
event:FireClient(player, "Class", "Bystander")
end
end
end
end
end
spawnsmodel:remove()
-- Wait for round end conditions
local localtimer = roundtime
while localtimer > 0 do
wait(1)
localtimer = localtimer - 1
timertag.Value = localtimer
activecontestants = {}
bloxxeractive = false
for _, player in pairs(contestants) do
if player then
local character = player.Character
if character then
local matchtag = character:FindFirstChild("MatchTag")
local humanoid = character:FindFirstChild("Humanoid")
if matchtag and humanoid and humanoid.Health > 0 then
if player == bloxxer then
bloxxeractive = true
end
table.insert(activecontestants, player)
end
end
end
end
if #activecontestants <= 1 or not bloxxeractive then
break
end
end
-- Sort game result
local gameresult = "PlayersWin"
if bloxxeractive then
if #activecontestants >= 2 then
event:FireAllClients("Result", "PlayersWin")
else
gameresult = "BloxxerWin"
event:FireAllClients("Result", "BloxxerWin")
end
else
event:FireAllClients("Result", "PlayersWin")
end
for _, v in pairs(game.Workspace:GetChildren()) do
if v then
if v.Name == "Pickup" or v.className == "Hat" then
v:remove()
end
end
end
for _, player in pairs(contestants) do
if player then
if gameresult == "BloxxerWin" and player == bloxxer then
awardwin(player)
awardpoints(player, 9)
elseif gameresult ~= "BloxxerWin" and player ~= bloxxer then
if player == sheriff then
awardwin(player)
awardpoints(player, 4)
else
awardwin(player)
awardpoints(player, 2)
end
end
end
end
-- Teleport plays back to lobby
local lobbyspawns = {}
for _, v in pairs(game.Workspace:WaitForChild("Lobby"):GetChildren()) do
if v and v.Name == "SpawnLocation" then
table.insert(lobbyspawns, v)
end
end
for _, player in pairs(activecontestants) do
if player then
awardpoints(player, 1)
if player.Character then
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
humanoid:UnequipTools()
end
end
local randomspawn = lobbyspawns[math.random(1, #lobbyspawns)]
player.Character:MoveTo(randomspawn.Position)
local backpack = player:FindFirstChild("Backpack")
if backpack then
backpack:ClearAllChildren()
end
end
end
bloxxer = nil
sheriff = nil
-- Intermission wait
statustag.Value = "Intermission"
timertag.Value = intermissiontime
local localtimer = intermissiontime
while localtimer > 0 do
wait(1)
localtimer = localtimer - 1
timertag.Value = localtimer
end
end