Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Could somebody fix this outdated script?

Asked by 9 years ago

A friend made it for me a while ago, I tried giving it a go myself but didn't really turn out well, could somebody explain to me what needs to be done/why and show me what it should look like once fixed? Here's the script:

math.randomseed(tick())

-- services
local teams = game:GetService("Teams");
local players = game:GetService("Players");
local lighting = game:GetService("ServerStorage");

-- teams
local crims = teams:WaitForChild("Criminals");
local polis = teams:WaitForChild("Police");
local specs = teams:WaitForChild("Spectators");

-- maps
-- I used a table in case you want to add more maps in the future:
-- all you'll need to do is insert `` lighting:WaitForChild("Map Name"); ``
local maps = {
lighting:WaitForChild("Night Store");
lighting:WaitForChild("Verkauf's Mansion");
lighting:WaitForChild("Day Store");
};

-- to make life easier
local function getCounts()
return #crims:GetChildren(), #polis:GetChildren();
end;

--[[ for the game ]]--
function connectDeath(player)
local char = player.Character;

-- wait for the character's humanoid to
-- exist
local humn = char:WaitForChild('Humanoid');

-- return the connection object
return humn.Died:connect(function()
player.TeamColor = specs.TeamColor;
end);
end;

function assignRandomRole(player)
local ccount, pcount = getCounts();

if ccount > pcount then
player.TeamColor = polis.TeamColor
elseif pcount > ccount then
player.TeamColor = crims.TeamColor
elseif ccount == pcount then
local mraa = math.random(1,2);

if mraa == 1 then
player.TeamColor = crims.TeamColor
elseif mraa == 2 then
player.TeamColor = polis.TeamColor
end
end

return player.TeamColor;
end;
--[[--------------]]--

while wait(1) do
-- local variables are faster,
-- however not always appropriate
local msg = Instance.new("Hint")
local rand = math.random(1,2)

-- necessary for the game
local ccount, pcount = getCounts();
local connections = { };

if #players:GetPlayers() > 1 then

msg.Parent = workspace;
msg.Text = 'The game is about to start!';
wait(5);

-- Find a map in the "maps" table with a
-- random index # ranging from 1 to the
-- number of given maps
local mc = maps[math.random(1, #maps)];

local pbase = workspace.policestation;
local cbase = workspace.criminalhideout;

-- Spawn locations for each team
local p_spawns = pbase.spawns:GetChildren();
local c_spawns = cbase.spawns:GetChildren();

mc.Parent = game.Workspace
local mapspawn = workspace:findFirstChild("mapmat");
mc:MoveTo(Vector3.new(mapspawn.Position.X, mapspawn.Position.Y/2, mapspawn.Position.Z))
msg.Parent = game.Workspace
msg.Text = "The map " .. mc.Name .. " has been chosen."

-- assign each player a role and connect the event
-- that neutralizes them when they are done
for _, player in pairs(players:GetChildren()) do
assignRandomRole(player);
table.insert(connections, connectDeath(player));

local translation = Vector3.new(math.random(-3, 3), 3, math.random(-3, 3));

if player.TeamColor == crims.TeamColor then
local spawn = c_spawns[math.random(1,#c_spawns)];
player.Character:WaitForChild('Torso').CFrame = spawn.CFrame+translation
elseif player.TeamColor == polis.TeamColor then
local spawn = p_spawns[math.random(1,#p_spawns)];
player.Character:WaitForChild('Torso').CFrame = spawn.CFrame+translation
end
end;

wait(3);

msg.Parent = nil; -- don't destroy it, we still need it!

-- wait until theres no players left on either team
-- by repeatidly getting the count of the teams
-- and checking to see if one equals zero
-- (this updates the variables until done)
repeat wait(1);
ccount, pcount = getCounts();
until ccount==0 or pcount==0;

msg.Parent = game.Workspace

-- if the count of police = 0 then
-- or if the count of criminals = 0 then
if pcount == 0 then
msg.Text = "The Criminals have won!"
elseif ccount == 0 then
msg.Text = "The Police have won!"
end;

-- neutralize all players
for _, player in pairs(players:GetChildren()) do
player.TeamColor = specs.TeamColor;
end;

-- disconnect all connections
for i, connection in next, connections do
connection:disconnect();
end;

wait(3)
msg:Destroy()
mc:Destroy()
else
msg.Parent = workspace
msg.Text = "You need 2 or more people to start the game."
wait(3);
msg:Destroy();
end
end

The idea of it is to equally split the players into the Criminals/Police teams, select a random map, teleport the players to the team spawns. when all of one team dies the other is crowned as winners OR if the time runs out (5 minutes) it ends as a draw. Then players will be changed to the spectator team and killed starting the game again after a minute of being in the lobby Here's the information you'd need for the script to make sense:

lobbyspawns (model) > spawn1 to spawn10

criminalhideout (model) > spawns (model) > spawn1 to spawn5

policestation (model) > spawns (model) > spawn1 to spawn5

mapmat

If you need more information, let me know. If you help, thank you:)

0
Yeah, this is a not a "I'M GONNA GIVE YOU THE WHOLE SCRIPT AND EXPECT YOU TO FIX IT" site. DevChris 235 — 9y
0
@devChris I was pretty certain my post was was following all the rules? Correct me if I'm mistaken. PrayForPIagues 0 — 9y
0
What is it not doing that it is supposed to be doing? 1waffle1 2908 — 9y
0
@1waffle1 Well, I can't explain fully what because I can't figure out what it's doing, when you play it, it teleports you correctly but doesn't load a map, then the game ends like one second later then it starts again ends like one second later then eventually stops doing that and does nothing PrayForPIagues 0 — 9y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

Line 81 should be changed so that it creates a clone of the map instead of using the prototype, because on line 147 you're destroying it.

0
Good eye, thanks. But now it stops working at "The game is about to start!" I can't exactly look for an output error when it's a two player needed team wins game:/ PrayForPIagues 0 — 9y
0
Start a network server with two players from studio. 1waffle1 2908 — 9y
0
I don't have anybody to do that nor know how PrayForPIagues 0 — 9y
0
Is there a way I can trick the server into thinking there are two players via models? PrayForPIagues 0 — 9y
View all comments (4 more)
0
Not if it's using GetPlayers or NumPlayers. You could just change the >1 to >0 though, or, you could go into studio and start a test server. 1waffle1 2908 — 9y
0
I know that but it'd just end because I'll be the only player remaining PrayForPIagues 0 — 9y
0
so make it not do that. 1waffle1 2908 — 9y
0
I realized that the error I'm getting isn't at the end of the script (where the game ends) so I did some solo stuff and realized I could use my phone for two players, thanks for the help PrayForPIagues 0 — 9y
Ad

Answer this question