I want the to script the select to Random players and teleport them to 2 different locations.
function start(plyr) if script.Parent.Text= "Start Match" then, if plyr.Character ~= nil then plyr.Character:MoveTo(Vector3.new(45.6, 213.604, 56.2)) else ranPlyr() end end function ranPlyr() if #players > 2 then local a = math.random(1, game.Players.NumPlayers) plyrs = game.Players:GetChildren() for i = 1, #plyrs do rand = plyrs[a] end start(rand) else message.Parent = game.Workspace wait(4) message.Parent = nil end end while true do wait(10) ranPlyr() end
Your script has syntax error.
Use your output. It would tell you exactly what is wrong:
input:2: 'then' expected near '='
We have a problem on the second line near the =
.
The operator which compares values is ==
.
Use ==
for comparison instead of =
which is used for assignment:
if script.Parent.Text == "Start Match" then
We have another syntax error.
input:2: unexpected symbol near ','
That comma is superfluous and wrong. Remove it.
Yet another syntax error. Maybe you should review your basic Lua. Definitely learn to use your output
input:30: 'end' expected (to close 'function' at line 1) near <eof>
Tab and space your code properly. If we do, we can see problems like this easily:
function start(plyr) if script.Parent.Text== "Start Match" then if plyr.Character ~= nil then plyr.Character:MoveTo(Vector3.new(45.6, 213.604, 56.2)) else ranPlyr() end end function ranPlyr() if #players > 2 then local a = math.random(1, game.Players.NumPlayers) plyrs = game.Players:GetChildren() for i = 1, #plyrs do rand = plyrs[a] end start(rand) else message.Parent = game.Workspace wait(4) message.Parent = nil end end while true do wait(10) ranPlyr() end
Clearly (with tabs) we can see something is wrong. We didn't return to no indentation before defining ranPlyr
so we're probably missing something above.
Add an end
to close start
.
You use the variable players
but never define it. You define a similarly named plyrs
which isn't used a little below. We should move that up:
players = game.Players:GetChildren() if #players > 2 then local a = math.random(1, game.Players.NumPlayers)
Note that it is more proper to use :GetPlayers()
to get a list of players. Also note that game.Players.NumPlayers
is a really long way to use what you've already used: #players
.
We should also use players
instead of plyrs
then from now. (Really -- use readable, normal variable names)
Your for
loop on line 15 is pointless.
i
and doesn't change anything it uses)You use message
but never define it.
Warning: If there are more than two players, but none of them have Characters, then your script will have a stack-overflow-error. In that case, start(rand)
will call ranPlyr()
repeatedly.
You should have some sort of bailout to be sure. For example, you should instead make a list of alive-players and considers its length rather than the number of players.