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

Why is my 'Control Points' script erroring?

Asked by 9 years ago

I have conducted allot of tests to try and get the script to work, but it keeps erroring each time, it worked perfectly fine yesterday, but now it broke, now before you guys thumbs down this [like you did the last time], this was originally a project someone and I were working on, but the other person abandoned the project and I decided to keep it going, this script was ,INFACT, made 100% by me, TheeDeathCaster/TheAlphaStigma [Just a heads up, this was not stolen NOR copied], moving on, the Output keeps saying 16:34:57.303 - Workspace.MainScript:49: bad argument #2 to '?' (Vector3 expected, got userdata) 16:34:57.304 - Script 'Workspace.MainScript', Line 49 - upvalue SetSpawn 16:34:57.305 - Script 'Workspace.MainScript', Line 81 - upvalue BalanceTeams 16:34:57.305 - Script 'Workspace.MainScript', Line 96 - local Leader 16:34:57.306 - Script 'Workspace.MainScript', Line 111 16:34:57.307 - Stack End, but I do not know what it means by that, nor how to fix the problem, here is the script [I have commented all current errors where they happen];

--Raidable Points Script [!BETA!] This script is still being developed


local GameTime = .5 --Change to how many minutes you want the game to play for [This was a reminder to help me remember that this is the 'GameTime', for how long the game runs]
local RedTeam = nil
local BlueTeam = nil
local RedTeamPoint = game.Workspace:WaitForChild("RedTeam")
local RedTeamPointScript = RedTeamPoint:WaitForChild("Script")
local BlueTeamPoint = game.Workspace:WaitForChild("BlueTeam")
local BlueTeamPointScript = BlueTeamPoint:WaitForChild("Script")
local BlueSpawn = game.Workspace:WaitForChild("BlueTeamSpawn")
local RedSpawn = game.Workspace:WaitForChild("RedTeamSpawn")
local Blues = {}
local Reds = {}
local Randomize = {"Reds","Blues"}
local TeamPoints1 = game.Workspace:WaitForChild("BluePoints")
local TeamPoints2 = game.Workspace:WaitForChild("RedPoints")
local GameTimer = game.Workspace:WaitForChild("GameTimer")

local function Msg(msg,par)
local M = Instance.new("Message",par)
for i = 1, #msg do
M.Text = msg:sub(1,i)
wait(1/19)
end
wait(#msg/19+4.5)
if M then
M:Destroy()
end
end

if game:FindFirstChild("Teams") then
RedTeam = game.Teams:WaitForChild("RedTeam")
BlueTeam = game.Teams:WaitForChild("BlueTeam")
else
print("ERROR: ","'Teams' service does not exist! The script may malfunction!")
end

local function SetSpawn(plr)
if plr and plr.TeamColor == RedTeam.TeamColor then
if plr.Character and plr.Character:FindFirstChild("Torso") then
plr.Character.Torso.CFrame = CFrame.new(Vector3.new(0,1,0)+RedSpawn.CFrame) --Error here
elseif not plr.Character or not plr.Character:FindFirstChild("Torso") then
repeat wait() until plr.Character and plr.Character:FindFirstChild("Torso")
plr.Character.Torso.CFrame = CFrame.new(Vector3.new(0,1,0)+RedSpawn.CFrame)
end
elseif plr and plr.TeamColor == BlueTeam.TeamColor then
if plr and plr.Character and plr.Character:FindFirstChild("Torso") then
plr.Character.Torso.CFrame = CFrame.new(Vector3.new(0,1,0)+BlueSpawn.CFrame) --Error here
elseif not plr.Character or not plr.Character:FindFirstChild("Torso") then
repeat wait() until plr.Character and plr.Character:FindFirstChild("Torso")
plr.Character.Torso.CFrame = CFrame.new(Vector3.new(0,1,0)+BlueSpawn.CFrame)
end
else
print("Player not on either team! :O")
end
end

local function BalanceTeams(plr)
if #Blues > #Reds then --This should help balance out teams :)
plr.TeamColor = RedTeam.TeamColor
table.insert(Reds,plr.Name)
SetSpawn(plr)
Msg("Your on the Red team!",plr.PlayerGui)
elseif #Blues < #Reds then
plr.TeamColor = BlueTeam.TeamColor
table.insert(Blues,plr.Name)
SetSpawn(plr)
Msg("Your on the Blue team!",plr.PlayerGui)
else
if #Blues == #Reds then
local Random = Randomize[math.random(1,#Randomize)]
if Random == "Reds" then
plr.TeamColor = RedTeam.TeamColor
table.insert(Reds,plr.Name)
SetSpawn(plr) --Upvalue 'BalanceTeams'?! What?!
Msg("Your on the Red team!",plr.PlayerGui)
elseif Random == "Blues" then
plr.TeamColor = BlueTeam.TeamColor
table.insert(Blues,plr.Name)
SetSpawn(plr)
Msg("Your on the Blue team!",plr.PlayerGui)
end
end
end
end

local function Leader(plr)

local LeaderStats = Instance.new("IntValue",plr) LeaderStats.Name = "leaderstats"
local Points = Instance.new("IntValue",LeaderStats) Points.Name = "Points" Points.Value = 0
local Deaths = Instance.new("IntValue",LeaderStats) Deaths.Name = "Deaths" Deaths.Value = 0

if plr.Neutral then plr.Neutral = false end

BalanceTeams(plr) --local Leader?! o_e
plr.CharacterAdded:connect(function(char)
repeat wait() until plr and char and char:FindFirstChild("Humanoid") and char.Humanoid.Health ~= 0
SetSpawn(plr)
end)

end

local function PlayerRemove(plr)
for i = 1, #Reds do if plr.Name:lower() == Reds[i]:lower() then table.remove(Reds,plr.Name) end end
for i = 1, #Blues do if plr.Name:lower() == Blues[i]:lower() then table.remove(Blues,plr.Name) end end
end

game.Players.PlayerAdded:connect(Leader)
game.Players.PlayerAdded:connect(SetSpawn)
for i,v in pairs(game.Players:GetPlayers()) do Leader(v) end --Heh?!
for i,v in pairs(game.Players:GetPlayers()) do SetSpawn(v) end
game.Players.PlayerRemoving:connect(PlayerRemove)

coroutine.wrap(function()
while wait() do
TeamPoints1.Value = 0
TeamPoints2.Value = 0
RedTeamPointScript.Disabled = false
BlueTeamPointScript.Disabled = false
Msg("Let the games begin!",game.Workspace)
for z = GameTime*60,0,-1 do
GameTimer.Value = z
wait(1)
end
wait(.5)
RedTeamPointScript.Disabled = true
BlueTeamPointScript.Disabled = true
if TeamPoints1.Value > TeamPoints2.Value then
Msg("Blue team has won!",game.Workspace)
for i,v in pairs(game.Players:GetPlayers()) do if (v.TeamColor == BlueTeam.TeamColor) and v:FindFirstChild("leaderstats") and v.leaderstats:FindFirstChild("Points") then v.leaderstats.Points.Value = v.leaderstats.Points.Value + 5 end end
Msg("Points given to the Blue team!",game.Workspace)
elseif TeamPoints1.Value < TeamPoints2.Value then
Msg("Red team has won!",game.Workspace)
for i,v in pairs(game.Players:GetPlayers()) do if (v.TeamColor == RedTeam.TeamColor) and v:FindFirstChild("leaderstats") and v.leaderstats:FindFirstChild("Points") then v.leaderstats.Points.Value = v.leaderstats.Points.Value + 5 end end
Msg("Points given to the Red team!",game.Workspace)
else
if TeamPoints1.Value == TeamPoints2.Value then
Msg("It was a tie!",game.Workspace)
Msg("No points have been awarded D:",game.Workspace)
end
end
for i = 10, 0, -1 do
local MC = Instance.new("Message",game.Workspace)
MC.Text = "New round starts in: "..i
wait(1)
MC:Destroy()
end
for i,v in pairs(game.Players:GetPlayers()) do if v and v.Character then v.Character:BreakJoints() BalanceTeams(v) end end --To stop those who are fighting during the start of a new game
end
end)()

Why did I post the whole script, you may be wondering? I was told before on an old question to post the entire code for a better understanding. :P Control Points game

1 answer

Log in to vote
0
Answered by
RedCombee 585 Moderation Voter
9 years ago

Line 3: Your loop is not specifying what is to be nil.

0
Lol sorry, it's become a habit of me to add a 'repeat until nil' into scripts now. :P XD I know it's not required, it's just an old habit. XD There, I edited the Question. :P TheeDeathCaster 2368 — 9y
0
I know this is old, but this doesn't answer the question presented. TheeDeathCaster 2368 — 7y
Ad

Answer this question