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

Simple gamepass script not working?

Asked by 9 years ago

Hi guys! I am trying to make a simple x2 team chance but this is not working...any ideas? Thanks :)

id = 186964027
list = {}
function AddPlayers2()
for i,v in pairs (game.Players:GetChildren()) do
    table.insert(list,v)
if game:GetService("GamePassService"):PlayerHasPass(v,id) then
table.insert(list,v)
end
end
num1 = math.random(1,#list)
print(list[num1])
num1.TeamColor = BrickColor.Blue() --erroring but dont know why
num2 = math.random(1,#list)
num2.TeamColor = BrickColor.Blue()
if num2.Name == num1.name then
 repeat
  num2 = math.random(1,#list)
  num2.TeamColor = BrickColor.Blue()
 until
 num2.name ~= num1.Name
--how to put reamining non-picked players into another team?
end
end
0
BrickColor is only made for Parts, Use Color3.new. I believe that should do it. woodengop 1134 — 9y
0
No. http://wiki.roblox.com/index.php?title=API:Class/Player/TeamColor. VALUE: BrickColor. Please check the wiki before posting something you're not sure about. DigitalVeer 1473 — 9y
0
ok, sry. woodengop 1134 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

The reason you are getting an error is because you are not actually picking a player from the table, but merely trying to set the TeamColor of an Integer.

I also fixed some syntax errors and some redundancies. Let's look at a fix:

id = 186964027
list = {}

function AddPlayers2()
for i,v in pairs (game.Players:GetChildren()) do
if game:GetService("GamePassService"):PlayerHasPass(v,id) then
table.insert(list,v)
end
end
end

AddPlayers2() --Call function to make sure table isn't empty
local num1 = math.random(1,#list)
local plr1 = list[num1]
print(list[num1])
plr1.TeamColor = BrickColor.Blue()
local plr2
repeat
local num2 = math.random(1,#list)
plr2 = list[num2]
until plr2.Name ~= plr1.Name
plr2.TeamColor = BrickColor.Blue()

Ad

Answer this question