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

attempt to index field '?' (a nil value)?

Asked by 8 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.


local allPlayers = {} for a,v in pairs(game.Players:GetPlayers(2)) do table.insert(allPlayers,v) end local plrAmount = game.Players.NumPlayers math.randomseed(tick()) local val1 = game.Players.NumPlayers, plrAmount local val2 repeat wait(5) val2 = game.Players.NumPlayers until val2 ~=val1 allPlayers[val1].Character.Torso.CFrame = CFrame.new (0,0,0) allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)
0
its not changing into lua form sorry ): berrythebetta 20 — 8y
0
Select the whole script, press the Lua button. There should be one row of tildes (~~~~) above and one row below. You can edit your post by pressing the button at the right. BlueTaslem 18071 — 8y
0
now i got it :D thank you berrythebetta 20 — 8y
0
i got in in lua form ( i didnt fix the problem) ): berrythebetta 20 — 8y

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

First of all, you can't use HTML tags in Lua.

<pre class="brush: lua"> -- ... ... ...
 </pre> -- This isn't HTML, so this can't go in your script

Also, you can't put 2 in game.Players:GetPlayers(2). GetPlayers() is a function that gives you a table of the Players. It doesn't have any parameters.

I've added some annotations so you can read what is happening.

-- Pick two random players.
-- This is accomplished by creating a table of all Players, then picking two random numbers to correspond with players in the table. 


local allPlayers = game.Players:GetPlayers() --Create a table of all the players

-- #allPlayers is the amount of players in the game

math.randomseed(tick()) -- Seed the randomizer so we can get a different sequence each time we generate one

local val1 = math.random(1, #allPlayers) --Pick a random number between 1 and the amount of players (inclusive)


local val2;  --Predefine a variable for later

repeat val2 = math.random(#allPlayers) --Pick a random number again
until val2 ~=val1 --Keep picking a random number until it is different from the first random number

-- Now teleport the players that correspond with the two random numbers

allPlayers[val1].Character.Torso.CFrame = CFrame.new (0,0,0)
allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)

Also keep in mind this script will not work very well if there is only 1 player in the server. Be sure the script doesn't run unless there are two players in the server. I recommend checking the value of NumPlayers

if game.Players.NumPlayers > 1 then
    -- Code
end
Ad

Answer this question