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

attempt to call local 'plrs' (a table value) error?

Asked by 5 years ago

Hello I am new to coding and this one strip of code has gotten me stumped.
Here it is.

    if #plrs == 1 then
        --They won wow
        Status.Value = "The conquerer is.."..plrs(1).Name  --The error is this row
        plrs(1).leaderstats.Bucks.Value = plrs(1).leaderstats.Bucks.Value + reward
        break

plrs is a local table of how many players are left in the game and here i am trying to get their name to show up when they are the last player left alive. Though when there is one player left it just continues showing the status text that shows when the game is playing which is.

"There are # seconds remaining and # players remaining!"

When the players remaining goes down to 1 the status stops updating and says

"There are # seconds remaining and 1 players remaining!"

The seconds stop going down and nothing happens. What i want to happen is the status text to be updated to.

"The conquerer is.. (last person alive's name)!"

Thanks for help in advance.

0
Replace the `(1)` with `[1]` because you index tables using `brackets` not `parentheses` EpicMetatableMoment 1444 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Problem

attempt to call local 'plrs' (a table value) error?

What's wrong

The problem is in the error. You're trying to call plrs via () but plrs is a table {}; what you're doing --> plrs(...)

Solution

I assume you're trying to index the first player in the plrs array. When indexing an array using a number position you use brackets [].

Like this: plrs[1]

Code Example

local myTable = {
    "hehe",
    "epic"
}

local firstIndex = myTable[1] --// retreives the first index which is "hehe"
0
Thanks it worked! YTCommanderRE 2 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

When indexing an array, you should use square brackets instead of round bracket. So do players[1], not players(1)

Answer this question