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

Why is my 'Control Points' script erroring?

Asked by 9 years ago

I have done a few changes to the script, but it keeps erroring, the Output keeps saying 15:54:57.175 - Workspace.MainScript:43: bad argument #2 to '?' (Vector3 expected, got userdata) 15:54:57.176 - Script 'Workspace.MainScript', Line 43 - upvalue SetSpawn 15:54:57.177 - Script 'Workspace.MainScript', Line 71 - upvalue BalanceTeams 15:54:57.178 - Script 'Workspace.MainScript', Line 86 - local Leader 15:54:57.179 - Script 'Workspace.MainScript', Line 101 15:54:57.180 - Stack End, but, I don't know what to do anymore to fix it, it keeps saying this error everytime in Edit mode and Online mode [this just started recently, yesterday it worked fine], here is the script [I know, it's really messy coding ;-;];

--Raidable Points Script [!BETA!] This script is still being developed, so it may be buggy [This was originally a Project another person and I were working on, but the other person quit the project, I decided to keep it up]

repeat wait() break until nil
local GameTime = .5 --Change to how many minutes you want the game to play for [This is probly where you guys got the wrong idea; this is to help remind me that this is where you change the time for the game, incase I forget [originally to show the other person where the GameTime is]]
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) 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) 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)
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)
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
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)()

Ok, just got recently Thumbs'd down, I have created this script, here is the game: Control Points , I did not steal the script.

Answer this question