Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

0

Replace the (1) with [1] because you index tables using brackets not parentheses

2 answers

✓ Accepted answer

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"

1 comment

0

Thanks it worked!

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

This discussion is preserved as it was. New answers, comments, and votes are closed.