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 » Scripting Helpers
Home Search
 

Re: Randomizing and finding certain values.

Previous Thread :: Next Thread 
Diversified is not online. Diversified
Joined: 25 Jul 2011
Total Posts: 6
20 Jun 2012 03:42 PM
Alright, I'm having an issue with a script. I can't think of a decent solution to this issue, so here am I asking you guys. Heres the secenario, I am currently creating a game engine.

----------
Teams = {Red, Blue}
RedTeam = 0
BlueTeam = 0

game.Players.PlayerAdded:connect(function(player)
playar.Neutral = false
playar.TeamColor = Teams[math.random(1, #Teams)].TeamColor
end)

----------

Alright now, how would I change RedTeam, and BlueTeam values.. when a player joins the game and gets affected by the Randomizer. In other words, how would I find the player on what team the randomizer decides. Then change that value, so the next player gets the other TeamColor.
Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 03:44 PM
I spotted one. Teams = ("Red","Blue"). Use that.
Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 03:44 PM
sorry remove () and use {}
Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 03:45 PM
playar should be player also.
Report Abuse
Diversified is not online. Diversified
Joined: 25 Jul 2011
Total Posts: 6
20 Jun 2012 03:45 PM
.. Sigh, you didn't even read the post. I already have values for Red and Blue.
Report Abuse
Diversified is not online. Diversified
Joined: 25 Jul 2011
Total Posts: 6
20 Jun 2012 03:46 PM
.. The script above is fine- with a few minor mistakes on my behalf. You arn't answering my question.
Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 03:46 PM
So red and blue are string variables?
Report Abuse
Diversified is not online. Diversified
Joined: 25 Jul 2011
Total Posts: 6
20 Jun 2012 03:47 PM
Red = game.Teams["Red Recyclers"]
Blue = game.Teams["Blue Recyclers"]
Teams = {Red, Blue}
RedTeam = 0
BlueTeam = 0

game.Players.PlayerAdded:connect(function(player)
player.Neutral = false
player.TeamColor = Teams[math.random(1, #Teams)].TeamColor
end)


There, all the values are filled in and the mistakes.

Now please, answer my question.
Report Abuse
Diversified is not online. Diversified
Joined: 25 Jul 2011
Total Posts: 6
20 Jun 2012 03:48 PM
.. You arn't even reading my posts.

"Alright now, how would I change RedTeam, and BlueTeam values.. when a player joins the game and gets affected by the Randomizer. In other words, how would I find the player on what team the randomizer decides. Then change that value, so the next player gets the other TeamColor."

That question needs to be answered please.
Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 03:48 PM
Also, after the randomizer chooses do this (still in playerAdded event):


if player.TeamColor == "Bright red" then
red = 1
end


something like that.
Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 03:49 PM
also use an elseif statement for finding if it's blue.
Report Abuse
Diversified is not online. Diversified
Joined: 25 Jul 2011
Total Posts: 6
20 Jun 2012 03:51 PM
That wouldn't work- consider this. Player enters, few others join. The player then leaves.
Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 03:53 PM
You don't get what i'm trying to say. I'll just do it for you:


Red = game.Teams["Red Recyclers"]
Blue = game.Teams["Blue Recyclers"]
Teams = {Red, Blue}
RedTeam = 0
BlueTeam = 0

game.Players.PlayerAdded:connect(function(player)
player.Neutral = false
player.TeamColor = Teams[math.random(1, #Teams)].TeamColor
wait()
if player.TeamColor == Teams[1].TeamColor then
RedTeam = 1
elseif player.TeamColor == Teams[2].TeamColor then
BlueTeam = 1
end
end)

Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 03:54 PM
OHHHHH sorry i wasn't reading your post carefully, let me make a nother 1 sec.
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
20 Jun 2012 03:56 PM
If you are making an engine, any randomization is not too good of an idea. You want everything to be strict and sure.

local Teams = {Red, Blue}
local RedTeam = 0
local BlueTeam = 0
local lastTeamColor = "None" -- Use string to save storage

game.Players.PlayerAdded:connect(function(player)
if lastTeamColor == "None" then
local chosenColor = Teams[math.random(1, #Teams)].TeamColor
player.Neutral = false
player.TeamColor = chosenColor
elseif lastTeamColor == Teams[1].TeamColor then
player.Neutral = false
lastTeamColor = Teams[2].TeamColor
player.TeamColor = Teams[2].TeamColor
elseif lastTeamColor == Teams[2].TeamColor then
player.Neutral = false
lastTeamColor = Teams[1].TeamColor
player.TeamColor = Teams[1].TeamColor
end)

See, game engines are typically lengthy, but they are always set to do something specific.
Report Abuse
mamaguy is not online. mamaguy
Joined: 07 Oct 2010
Total Posts: 7073
20 Jun 2012 03:59 PM
Red = game.Teams["Red Recyclers"]
Blue = game.Teams["Blue Recyclers"]
Teams = {Red, Blue}
RedTeam = 0
BlueTeam = 0

game.Players.PlayerAdded:connect(function(player)
player.Neutral = false
player.TeamColor = Teams[math.random(#Teams)].TeamColor

end)

if player.TeamColor == Red.TeamColor then
RedTeam = RedTeam +1
elseif player.TeamColor == Red.TeamColor then
BlueTeam = BlueTeam +1
end

One problem, what if there are ten players and 9 of them go to blue team?
To fix:



Red = game.Teams["Red Recyclers"]
Blue = game.Teams["Blue Recyclers"]
Teams = {Red, Blue}
RedTeam = 0
BlueTeam = 0

game.Players.PlayerAdded:connect(function(player)
player.Neutral = false
player.TeamColor = Teams[math.random(#Teams)].TeamColor



if player.TeamColor == Red.TeamColor then
RedTeam = RedTeam +1
elseif player.TeamColor == Red.TeamColor then
BlueTeam = BlueTeam +1
end

if RedTeam == BlueTeam then
player.TeamColor = BrickColor.new(BlueTeam.TeamColor)
elseif RedTeam > BlueTeam or RedTeam < BlueTeam then
return end
end)


Report Abuse
mamaguy is not online. mamaguy
Joined: 07 Oct 2010
Total Posts: 7073
20 Jun 2012 04:00 PM
Gar, he did what I did except his is better forget mine >:O
Sync- Sync- Synchronized dancing!
Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 04:00 PM
Red = game.Teams["Red Recyclers"]
Blue = game.Teams["Blue Recyclers"]
Teams = {Red, Blue}
ab = false
RedTeam = 0
BlueTeam = 0

game.Players.PlayerAdded:connect(function(player)
player.Neutral = false
player.TeamColor = Teams[math.random(1, #Teams)].TeamColor
if player.TeamColor == Teams[1].TeamColor then
if RedTeam > BlueTeam then
player.TeamColor = Teams[2].TeamColor
BlueTeam = BlueTeam + 1
else
RedTeam = RedTeam + 1
end
elseif player.TeamColor == Teams[2].TeamColor then
if BlueTeam > RedTeam then
player.TeamColor = Teams[1].TeamColor
RedTeam = RedTeam + 1
else
BlueTeam = BlueTeam + 1
end
end

end)

Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
20 Jun 2012 04:02 PM
Mine will error lol, nvm.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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