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

Attempt to index field "?" (a number value)?

Asked by 8 years ago

I made a script that chooses a random number between 1 and the amount of spawn points, but I can't get the player's Torso to move to the place I want. Any help?

Here's the script :

local button = script.Parent.spawnButton
local blackScreen = script.Parent.Parent.blackScreen
local spawned = game.Players.LocalPlayer.data.spawned
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local spawns = {}

for i, v in pairs(workspace.spawnPoints:GetChildren()) do
    table.insert(spawns, i)
    print("[SpawnCheck] Spawn " .. i .. " ready")
    wait()
end

button.MouseButton1Down:connect(function()
    for i = 1, 20 do
        blackScreen.BackgroundTransparency = blackScreen.BackgroundTransparency - .05
        wait(.025)
    end
    print("[SpawnCheck] Teleport started")
    local n = math.random(#spawns)
    humanoid.Parent.Torso.CFrame = CFrame.new(spawns[n].Position)
    print("[SpawnCheck] Teleport finished")
end)

The error message I get in the output is exactly this : 10:43:09.838 - Players.Player1.PlayerGui.main.rightSide.spawnHandler:20: attempt to index field '?' (a number value)

1 answer

Log in to vote
2
Answered by 8 years ago

Line 8:

table.insert(spawns, i)

That's incorrect. You're inserting the *index *into the table. You want to insert the value of that index, which is "v" in this case. Change that line to:

table.insert(spawns, v)
0
Thank you. I'm pretty new to table functions TheArmoredReaper 173 — 8y
0
No problem! Just takes some practice. crazyman32 30 — 8y
Ad

Answer this question