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

"Attempt to index field '?' (nil value)" [SOLVED]

Asked by 6 years ago
Edited 6 years ago

Whenever I try to run the script, the output just says "ServerScriptService.Script:14: attempt to index field '?' (a nil value)" I don't know what's happening, because if I remove the CFrame, the output just says "expecting CFrame". Help?

local MapsLocation = ServerStorage:WaitForChild("Maps")
local plrs = {}
local GetMaps = MapsLocation:GetChildren()
local MapToAppear = GetMaps[math.random(1, #AVMaps)]
local MapCloned = MapToAppear:Clone()
MapCloned.Parent = game.Workspace
local SpawnBricks = MapCloned:FindFirstChild("Spawn")
local SpawnsToTeleport = SpawnBricks:GetChildren()
wait(3)
    for i, plr in pairs(plrs) do
        if plr then
            char = plr.Character
            if char then
                char:FindFirstChild("HumanoidRootPart").CFrame = SpawnsToTeleport[1].CFrame
                table.remove(SpawnsToTeleport, 1)
            end
0
try printing spawnstoteleport[1] and see what you get DinozCreates 1070 — 6y
0
Prints nil (already tried that earlier), but the problem is that if i remove the [1], it will give an error ("bad argument #3, expecting CFrame) Goomiin 1 — 6y
0
if its printing nil your table probably doesnt have anything in it, so obviously it cant get cframe information from nothing. DinozCreates 1070 — 6y

2 answers

Log in to vote
0
Answered by
Vmena 87
6 years ago
Edited 6 years ago

It's because you are indexing an empty table, you have no value for the player in the table. local plrs = {} -- Empty table

for i, plr in pairs(plrs) do -- indexing empty table

char:FindFirstChild("HumanoidRootPart").CFrame = SpawnsToTeleport[1].CFrame -- indexing nil value

0
I didn't include some parts of the actual script as those are the most important. There is a table.insert, which redirects the player name to the table. Goomiin 1 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

So, I discovered that I could use the variable SpawnsToTeleport, use it as a table and put the SpawnBricks variable in.

local MapsLocation = ServerStorage:WaitForChild("Maps")
local plrs = {}
local GetMaps = MapsLocation:GetChildren()
local MapToAppear = GetMaps[math.random(1, #AVMaps)]
local MapCloned = MapToAppear:Clone()
MapCloned.Parent = game.Workspace
local SpawnBricks = MapCloned:FindFirstChild("Spawn")
local SpawnsToTeleport = {SpawnBricks}
wait(3)
for i, plr in pairs(plrs) do
    if plr then
        char = plr.Character
        if char then
            char:FindFirstChild("HumanoidRootPart").CFrame = SpawnsToTeleport[1].CFrame
            table.remove(SpawnsToTeleport, 1)
        end

It didn't give me the error again, so yay?

0
SpawnsToTeleport[1].CFrame, Change to: CFrame.new(SpawnsToTeleport[1].CFrame.Position) yHasteeD 1819 — 6y
0
@yHasteeD, the script actually takes me to the position I want without having to type CFrame.new and CFrame.Position. Goomiin 1 — 6y

Answer this question