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: In need of help, message command

Previous Thread :: Next Thread 
Evess is not online. Evess
Joined: 27 May 2012
Total Posts: 25583
24 Dec 2012 09:38 AM
I tried to make a script that would randomize two teams when an admin would say "scramble teams".

It doesn't seem to work and I can't see the output because it's a chat command.

This is what I got;

function command(msg,speaker)
if string.lower(msg) == "scramble teams" then
if speaker.Name == "Evess" then
_G.Teams = {}
_G.Teams["Red team"] = {}
_G.Teams["Blue team"] = {}
local plrs=randomizetable(game.Players:GetChildren())
for i,v in ipairs(plrs) do
if v~=nil and v.Parent~=nil then
local t = (i%(#teams))+1
v.TeamColor=teams[t].color
_G.Teams[teams[t].name][v.Name] = v
end end end end end
Report Abuse
FreeToTake is not online. FreeToTake
Joined: 21 Apr 2010
Total Posts: 1827
24 Dec 2012 09:57 AM
local function shuffle(t)
local n = #t
while n >= 2 do
local k = math.random(n)
t[n], t[k] = t[k], t[n]
n = n - 1
end
return t
end

function command(msg, speaker)
if msg:lower() == "scramble teams" then
if speaker.Name == "Evess" then
_G.Teams = {["Red team"] = {}, ["Blue team"] = {}}
local players = shuffle(game.Players:GetChildren())
for _,p in ipairs(players) do
p.TeamColor = _G.Teams["Blue team"]
end
for x = 1, math.floor(#players/2) do
players[x].TeamColor = _G.Teams["Red team"]
end
end end end
Report Abuse
Evess is not online. Evess
Joined: 27 May 2012
Total Posts: 25583
24 Dec 2012 01:11 PM
It didn't work so I put it in a while true do loop instead.

This is the error I got;

Workspace.Team Scrambler:15: bad argument #3 to 'TeamColor' (BrickColor expected, got table)

Line 15 is "p.TeamColor = _G.Teams["Blue team"] "
Report Abuse
Evess is not online. Evess
Joined: 27 May 2012
Total Posts: 25583
24 Dec 2012 02:15 PM
.
Report Abuse
Moolah60 is not online. Moolah60
Joined: 26 Sep 2009
Total Posts: 654
24 Dec 2012 02:20 PM
You needed to have it so it set the players team color to an actual BrickColor value, before it was setting _G.Teams["Red team"] to a table rather than to a brick color and then trying to set the players teamcolor as a table. This should work.

local function shuffle(t)
local n = #t
while true do
if n >1 do
local k = math.random(n)
t[n], t[k] = t[k], t[n]
n = n - 1
end
wait()
end
return t
end

function command(msg, speaker)
if msg:lower() == "scramble teams" then
if speaker.Name == "Evess" then
_G.Teams = {["Red team"] = BrickColor.new("Bright red"), ["Blue team"] = BrickColor.new("Bright blue")}
local players = shuffle(game.Players:GetChildren())
for _,p in ipairs(players) do
p.TeamColor = _G.Teams["Blue team"]
end
for x = 1, math.floor(#players/2) do
players[x].TeamColor = _G.Teams["Red team"]
end
end end end
Report Abuse
Moolah60 is not online. Moolah60
Joined: 26 Sep 2009
Total Posts: 654
24 Dec 2012 02:21 PM
I always mess up on the forums.. now it should work.

local function shuffle(t)
local n = #t
while true do
if n >1 then
local k = math.random(n)
t[n], t[k] = t[k], t[n]
n = n - 1
end
wait()
end
return t
end

function command(msg, speaker)
if msg:lower() == "scramble teams" then
if speaker.Name == "Evess" then
_G.Teams = {["Red team"] = BrickColor.new("Bright red"), ["Blue team"] = BrickColor.new("Bright blue")}
local players = shuffle(game.Players:GetChildren())
for _,p in ipairs(players) do
p.TeamColor = _G.Teams["Blue team"]
end
for x = 1, math.floor(#players/2) do
players[x].TeamColor = _G.Teams["Red team"]
end
end end end
Report Abuse
Evess is not online. Evess
Joined: 27 May 2012
Total Posts: 25583
25 Dec 2012 01:38 PM
It doesn't work for me.
I put it in a while wait(1) do form instead of admin chat, and there's no output at all.
Report Abuse
gerit99 is not online. gerit99
Joined: 21 Jul 2010
Total Posts: 521
25 Dec 2012 01:48 PM
Is it me or should p.TeamColor = _G.Teams["Blue team"]
be p.TeamColor = _G.Teams["Blue team"].TeamColor

Report Abuse
Evess is not online. Evess
Joined: 27 May 2012
Total Posts: 25583
25 Dec 2012 08:28 PM
Maybe, I don't know.
I think the output would have made an error if that was the case.
Report Abuse
SamuelKingx is not online. SamuelKingx
Joined: 27 Jan 2012
Total Posts: 3472
25 Dec 2012 08:31 PM
@Evess, I've learned that even though there's no output, that doesn't mean there's no errors. I've made scripts before where I purposely added errors, and the output never found them.

~SamuelKingx~LuaLearners Teacher(+2)
Report Abuse
Evess is not online. Evess
Joined: 27 May 2012
Total Posts: 25583
26 Dec 2012 08:03 AM
I thought only logical mistakes didn't make any output.
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