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

Why do I get this error? attempt to call local 'spawns' (a table value)

Asked by 6 years ago

Okay so I am making a sword fighting game and I get this error: ServerScriptService.MainScript:26: attempt to call local 'spawns' (a table value) So what the script does is it updates a text label (How much more time in intermission and when the game is starting)It picks a random map from serverstorage then teleport the players to parts named Spawn but I get that error when it is supposed to teleport them. Please help. Here is the script (A block of code is written in comment for testing)

local replicatedstorage = game:GetService("ReplicatedStorage")
local status = replicatedstorage:WaitForChild("InfoValue")
local mapstorage = game.Workspace:WaitForChild("mapStorage")
while true do
--[[
while game.Players.NumPlayers < 2 do
    status.Value = "There needs to be 2 or more players to begin the game."
    repeat wait(2) until game.Players.NumPlayers >= 2
end
]]
for i = 15,0,-1 do
    status.Value = "Intermission "..i
    wait(1)
end

local mapsinserverstorage = game:GetService("ServerStorage"):GetChildren()
local chosenmap = mapsinserverstorage[math.random(1,#mapsinserverstorage)]
chosenmap:Clone().Parent = mapstorage
status.Value = "Get ready to play!"
wait(3)
local spawns = chosenmap:WaitForChild("Spawns"):GetChildren()
for _, player in pairs(game.Players:GetPlayers()) do
    if player and #spawns > 0 then
        local torso = player.Character:WaitForChild("HumanoidRootPart")
        local allspawns = math.random(1,#spawns)
        local randomspawn = spawns(allspawns)
        if randomspawn and torso then
            table.remove(spawns,allspawns)
            torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0))
        end
    end
end




wait(30)




mapstorage:ClearAllChildren()
end

1 answer

Log in to vote
0
Answered by
lukeb50 631 Moderation Voter
6 years ago
spawns(allspawns)

Is how you call a function, not get a value from a table. Using brackets will fix your issue

        local randomspawn = spawns[allspawns]
0
Thank you so much! ElementedHero 0 — 6y
0
Would you mind accepting the answer? lukeb50 631 — 6y
Ad

Answer this question