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: Global Tables

Previous Thread :: Next Thread 
Hibobb is not online. Hibobb
Joined: 18 Apr 2010
Total Posts: 2146
08 Apr 2014 05:48 PM
Must they be defined in all scripts? I define _G.redteam = {} in a leaderboard script(since it runs first), but my gamescript that sorts teams does not seem to be able to insert players into the table. I do print(#_G.redteam) and it always returns zero. This is not in play solo either
Report Abuse
TaaRt is not online. TaaRt
Joined: 26 Apr 2009
Total Posts: 5039
08 Apr 2014 05:54 PM
You define a global like _G["redteam"] = {}
Report Abuse
Hibobb is not online. Hibobb
Joined: 18 Apr 2010
Total Posts: 2146
08 Apr 2014 06:02 PM
Can you not do?
_G.redteam = {}
Report Abuse
TaaRt is not online. TaaRt
Joined: 26 Apr 2009
Total Posts: 5039
08 Apr 2014 06:04 PM
I'm here to tell you my solution isn't necessary the way you are using does work but just not for you.
Report Abuse
Mlatu is not online. Mlatu
Joined: 01 Aug 2011
Total Posts: 540
08 Apr 2014 06:04 PM
If it is a localscript, then the script won't be able to access the global tables (_G & shared).
Report Abuse
Hibobb is not online. Hibobb
Joined: 18 Apr 2010
Total Posts: 2146
08 Apr 2014 06:12 PM
Its is not local
Report Abuse
Mlatu is not online. Mlatu
Joined: 01 Aug 2011
Total Posts: 540
08 Apr 2014 06:14 PM
Maybe you aren't entering the correct values into the table! It would be easier to help you if you show us that part of the script.
Report Abuse
Hibobb is not online. Hibobb
Joined: 18 Apr 2010
Total Posts: 2146
08 Apr 2014 06:17 PM
Multiple scripts in fact. Look at very last one and look for the designated line.

Leaderboard:
_G.players = {}
_G.redteam = {}
_G.blueteam = {}
_G.inprogress = false

game.Players.PlayerAdded:connect(function(player)
if _G.inprogress == false then
table.insert(_G.players,player)
elseif _G.inprogress == true then
table.insert(_G.players,player)
if #_G.redteam < #_G.blueteam then
player.TeamColor = BrickColor.Red()
player.Neutral = false
table.insert(_G.redteam,v)
if Workspace.MainScript.Current.Value == "Destruction:Round1" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = false
elseif Workspace.MainScript.Current.Value == "Destruction:Round2" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = true
end
elseif #_G.blueteam < #_G.redteam then
player.TeamColor = BrickColor.new("Bright bluish green")
player.Neutral = false
table.insert(_G.blueteam,v)
if Workspace.MainScript.Current.Value == "Destruction:Round1" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = true
elseif Workspace.MainScript.Current.Value == "Destruction:Round2" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = false
end
elseif #_G.redteam == #_G.blueteam then
player.TeamColor = BrickColor.Red()
player.Neutral = false
table.insert(_G.redteam,v)
if Workspace.MainScript.Current.Value == "Destruction:Round1" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = false
elseif Workspace.MainScript.Current.Value == "Destruction:Round2" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = true
end
end
end

GameScript:

function divide()
blue = Instance.new("Team",game.Teams)
blue.Name = "Osprey"
blue.AutoAssignable = false
blue.AutoColorCharacters = false
blue.TeamColor = BrickColor.new("Bright bluish green")
red = Instance.new("Team",game.Teams)
red.Name = "Dragonfly"
red.AutoAssignable = false
red.AutoColorCharacters = false
red.TeamColor = BrickColor.Red()
a = true
for i,v in pairs(_G.players) do
if a then
v.TeamColor = BrickColor.Red()
table.insert(_G.redteam,v)
a = false
elseif not a then
v.TeamColor = BrickColor.new("Bright bluish green")
table.insert(_G.blueteam,v)
a = true
end
end
end

Script I Am Having Problems With:

player = script.Parent.Parent.Parent.Parent.Parent.Parent
print("1")
if player.TeamColor == game.Teams.Dragonfly.TeamColor then
print("GO")
print(#_G.redteam)--HERE! This is printing 0 even though there should be at least one player in it
for _,v in pairs(_G.redteam) do
print("YES")
if v ~= player then
print("2")
local board = Instance.new("BillboardGui",player.PlayerGui)
board.AlwaysOnTop = false
board.Size = UDim2.new(1,0,1,0)
board.StudsOffset = Vector3.new(0,2,0)
board.Adornee = v.Character.Head
print("3")
local n = Instance.new("TextLabel",board)
n.BackgroundTransparency = 1
n.Position = UDim2.new(0.5,-50,0.5,-15)
n.Size = UDim2.new(0, 100,0, 30)
n.Font = "SourceSansBold"
n.FontSize = "Size14"
n.TextColor3 = Color3.new(0,1,0)
n.Text = ""..v.Name..""
print("4")
local board = Instance.new("BillboardGui",v.PlayerGui)
board.AlwaysOnTop = false
board.Size = UDim2.new(1,0,1,0)
board.StudsOffset = Vector3.new(0,2,0)
board.Adornee = player.Character.Head
print("5")
local n = Instance.new("TextLabel",board)
n.BackgroundTransparency = 1
n.Position = UDim2.new(0.5,-50,0.5,-15)
n.Size = UDim2.new(0, 100,0, 30)
n.Font = "SourceSansBold"
n.FontSize = "Size14"
n.TextColor3 = Color3.new(0,1,0)
n.Text = ""..player.Name..""
print("6")
end
end
end
Report Abuse
Mlatu is not online. Mlatu
Joined: 01 Aug 2011
Total Posts: 540
08 Apr 2014 06:27 PM
Your ends in the first part are wrong.

Here is the fixed version of the first part:

_G.players = {}
_G.redteam = {}
_G.blueteam = {}
_G.inprogress = false

game.Players.PlayerAdded:connect(function(player)
if _G.inprogress == false then
table.insert(_G.players,player)
elseif _G.inprogress == true then
table.insert(_G.players,player)
if #_G.redteam < #_G.blueteam then
player.TeamColor = BrickColor.Red()
player.Neutral = false
table.insert(_G.redteam,v)
if Workspace.MainScript.Current.Value == "Destruction:Round1" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = false
elseif Workspace.MainScript.Current.Value == "Destruction:Round2" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = true
end
elseif #_G.blueteam < #_G.redteam then
player.TeamColor = BrickColor.new("Bright bluish green")
player.Neutral = false
table.insert(_G.blueteam,v)
if Workspace.MainScript.Current.Value == "Destruction:Round1" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = true
elseif Workspace.MainScript.Current.Value == "Destruction:Round2" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = false
end
elseif #_G.redteam == #_G.blueteam then
player.TeamColor = BrickColor.Red()
player.Neutral = false
table.insert(_G.redteam,v)
if Workspace.MainScript.Current.Value == "Destruction:Round1" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = false
elseif Workspace.MainScript.Current.Value == "Destruction:Round2" then
local value = Instance.new("BoolValue",player)
value.Name = "Attacking"
value.Value = true
end
end
end
end)

function divide()
blue = Instance.new("Team",game.Teams)
blue.Name = "Osprey"
blue.AutoAssignable = false
blue.AutoColorCharacters = false
blue.TeamColor = BrickColor.new("Bright bluish green")
red = Instance.new("Team",game.Teams)
red.Name = "Dragonfly"
red.AutoAssignable = false
red.AutoColorCharacters = false
red.TeamColor = BrickColor.Red()
a = true
for i,v in pairs(_G.players) do
if a then
v.TeamColor = BrickColor.Red()
table.insert(_G.redteam,v)
a = false
elseif not a then
v.TeamColor = BrickColor.new("Bright bluish green")
table.insert(_G.blueteam,v)
a = true
end
end
end
Report Abuse
Hibobb is not online. Hibobb
Joined: 18 Apr 2010
Total Posts: 2146
08 Apr 2014 07:46 PM
What was wrong with them?
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