generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Team Spawning script

Previous Thread :: Next Thread 
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
22 Jan 2015 02:53 PM
I have this located in a Gui Button and no output error appears can someone tell me whats wrong with it? When you click the button its supposed to spawn you on the team with less players and if the teams are equal then it puts you on Team 1.


Teams = game:GetService("Teams")
Player = script.Parent.Parent.Parent.Parent.Parent -- Keep adding ".Parent" until you reach the Player

Team1 = Teams["Bright blue Team"]
Team2 = Teams["Bright yellow Team"]

function GetMembersOnTeam(Color)
local Count = 0 -- Starts at 0.

for i, v in pairs(game.Players:GetPlayers()) do -- Looks through all the Players
if tostring(v.TeamColor) == Color or v.TeamColor == Color then -- Checks Players' Team Colors.
Count = Count + 1 -- Increases value of Count
end
end
return Count
end

script.Parent.MouseButton1Click:connect(function()

local count1 = GetMembersOnTeam(Team1.TeamColor)
local count2 = GetMembersOnTeam(Team2.TeamColor)



if count2 > count1 then
Player.TeamColor = Team2.TeamColor
else
Player.TeamColor = Team1.TeamColor
end

-- Respawns character

Player:LoadCharacter()

end)
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
22 Jan 2015 03:18 PM
local plr = game.Players.LocalPlayer
local teamNumber1 = 0
local teamNumber2 = 0
local team1 = 'Bright Blue'
local team2 = 'Bright Yellow'

function Set()
if teamNumber1 > teamNumber2 then
plr.TeamColor = team2
elseif
teamNumber1 < teamNumber2 then
plr.TeamColor = team1
elseif
teamNumber1 == teamNumber2 then
--do math.random or watever u like, I'll just put him to Team1
plr.TeamColor = team1
end
end

function Get(Color)
for _, p in pairs(game.Players:GetChildren()) do --I trust GetChildren() more
if p.TeamColor == Color then
teamNumber1 = teamNumber1 + 1 --chance teamNumber1 to teamNumber2 if ur using that Team's Color
else
teamNumber2 = teamNumber2 + 1 --again, change if u want, but it must be the opposite Team than the one above!
Set()
end
end
end

Get(team1)

make sure it's all in a LocalScript!
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
22 Jan 2015 03:20 PM
oops, forgot...

plr:LoadCharacter()
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
22 Jan 2015 03:26 PM
Do I need to add the script.Parent.MouseButton1Down:connect(function() to this?
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
22 Jan 2015 03:36 PM
oh yeah, sry I forgot...

MouseButton1Click:connect(Get(team1))
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
22 Jan 2015 06:30 PM
Yea its not working...
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
23 Jan 2015 10:52 AM
local plr = game.Players.LocalPlayer
local teamNumber1 = 0
local teamNumber2 = 0
local team1 = 'Bright Blue'
local team2 = 'Bright Yellow'

function Set()
if teamNumber1 > teamNumber2 then
plr.TeamColor = team2
elseif
teamNumber1 < teamNumber2 then
plr.TeamColor = team1
elseif
teamNumber1 == teamNumber2 then
--do math.random or watever u like, I'll just put him to Team1
plr.TeamColor = team1
end
end

function Get(Color)
for _, p in pairs(game.Players:GetChildren()) do --I trust GetChildren() more
if p.TeamColor == Color then
teamNumber1 = teamNumber1 + 1 --chance teamNumber1 to teamNumber2 if ur using that Team's Color
else
teamNumber2 = teamNumber2 + 1 --again, change if u want, but it must be the opposite Team than the one above!
Set()
end
end
end

guiNamehere.MouseButton1Click:connect(Get(team1)) --change guiNamehere to the Button ur using (if the Script is inside the Button then script.Parent)
if guiNamehere.MouseButton1Click:connect(Get(team1)) didn't work then do

guiNamehere.MouseButton1Click:connect(function()
Get(team1)
end) --if the one above didn't work then this one should...

plr:LoadCharacter()
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
23 Jan 2015 05:07 PM
Okay its still not working heres the output errors:

18:06:13.348 - Players.Player.PlayerGui.ScreenGui.Frame.TextButton.LocalSc:13: bad argument #3 to 'TeamColor' (BrickColor expected, got string)
18:06:13.349 - Script 'Players.Player.PlayerGui.ScreenGui.Frame.TextButton.LocalSc', Line 13 - global Set
18:06:13.349 - Script 'Players.Player.PlayerGui.ScreenGui.Frame.TextButton.LocalSc', Line 27 - global Get
18:06:13.350 - Script 'Players.Player.PlayerGui.ScreenGui.Frame.TextButton.LocalSc', Line 33

and heres the script I used:


local plr = game.Players.LocalPlayer
local teamNumber1 = 0
local teamNumber2 = 0
local team1 = 'Bright Blue'
local team2 = 'Bright Yellow'

function Set()
if teamNumber1 > teamNumber2 then
plr.TeamColor = team2
elseif
teamNumber1 < teamNumber2 then
plr.TeamColor = team1
elseif
teamNumber1 == teamNumber2 then
--do math.random or watever u like, I'll just put him to Team1
plr.TeamColor = team1
end
end

function Get(Color)
for _, p in pairs(game.Players:GetChildren()) do --I trust GetChildren() more
if p.TeamColor == Color then
teamNumber1 = teamNumber1 + 1 --chance teamNumber1 to teamNumber2 if ur using that Team's Color
else
teamNumber2 = teamNumber2 + 1 --again, change if u want, but it must be the opposite Team than the one above!
Set()
end
end
end

script.Parent.MouseButton1Click:connect(function()
Get(team1)
end) --if the one above didn't work then this one should...

plr:LoadCharacter()
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
23 Jan 2015 06:32 PM
change

local team1 = 'Bright Blue'
local team2 = 'Bright Yellow'

to

local team1 = 'Bright blue'
local team2 = 'Bright yellow'

cos I forgot about Capitals
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
23 Jan 2015 06:58 PM
Still get an error message on line 33
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
24 Jan 2015 09:32 AM
Tested this (not on Server cos too long to wait and there are Problems in my Studio)

local plr = game.Players.LocalPlayer
_G.teamNumber1 = 0
_G.teamNumber2 = 0
local team1 = BrickColor.new('Bright blue')
local team2 = BrickColor.new('Bright yellow')

function Set()
if _G.teamNumber1 > _G.teamNumber2 then
plr.TeamColor = team2
_G.teamNumber2 = _G.teamNumber2 + 1
elseif
_G.teamNumber1 < _G.teamNumber2 then
plr.TeamColor = team1
_G.teamNumber1 = _G.teamNumber1 + 1
elseif
_G.teamNumber1 == _G.teamNumber2 then
--do math.random or watever u like, I'll just put him to Team1
plr.TeamColor = team1
_G.teamNumber1 = _G.teamNumber1 + 1
end
plr.Neutral = false
end

script.Parent.MouseButton1Click:connect(function()
Set()
plr:LoadCharacter()
end)

should Work...
I Tested this in Solo Mode
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
24 Jan 2015 11:08 AM
It works in my testing place but not in the actual place where I want to use it? Do you know of any reason why?
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
24 Jan 2015 11:10 AM
Okay it works there now too except it doesnt actually spawn you on that teams spawn it just switches your team?
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
24 Jan 2015 12:18 PM
are the Spawns just Bricks that are called Spawns or are they the proper ROBLOX Spawns???
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
24 Jan 2015 01:19 PM
There the actual Roblox spawns. I have 1 yellow spawn and 1 blue spawn and also 4 neutral spawns but it changes the team to bright blue team but it spawns you on a random spawn.
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
24 Jan 2015 04:09 PM
I dunno :/
something is really strange :/
it should Spawn ur Character on the Spawns wen the Character is Loaded...
are the Spawn's Property TeamColor set to the same as the Teams as well?
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
24 Jan 2015 04:41 PM
yes same color as teams
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
24 Jan 2015 04:42 PM
I do have them set to non-autoassignable because i dont want the players to spawn there when they join.
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
24 Jan 2015 05:06 PM
I dunno, the only Problem I could think of was that the TeamColor property of the Spawn was set to something else...
so, sry that I cant help with Spawning, I helped as much as I could...
now I kinda needa get back to Developing... see ya
Report Abuse
austin10111213 is not online. austin10111213
Joined: 27 Nov 2008
Total Posts: 363
24 Jan 2015 06:04 PM
Thanks for getting me this far!
Report Abuse
KAAK82 is not online. KAAK82
Joined: 06 May 2014
Total Posts: 1166
24 Jan 2015 06:14 PM
np
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image