Inserting a value inside an inserted value in a table

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I want to insert a value inside an inserted valued
  2. What is the issue?
local matches = {}
local plr = game.Players.LocalPlayer
local val = 1

table.insert(matches, plr)
table.insert(matches[plr], val)

output returns an error
3. What solutions have you tried so far?
tried to search up in google, got no results related to this topic.

You should be able to just write matches[plr] = val.

4 Likes

try this :
matches[plr] = {
val = 1
}
or
matches[plr] = val

1 Like

Does it simply replaces the plr value with val? I’m trying to put the val inside a plr value not replace.

No, the plr variable will stay the same. Check out this page for an explanation of dictionaries.

The table.insert property inserts the value onto an array

local matches ={
[1]= plr
}

so your table[plr] would return nil

if you do

matches[plr] ={}

table.insert(matches[plr],val)

this would work since now matches[plr] has a value and is not nil

this would also work

matches[plr] ={val}

would automatically put it an array so the outcome will be

local matches = {
 [plr] = {
       [1] = val
    }
}
1 Like

-- Try this
local table = {}
local plr = game.Players.LocalPlayer
table.insert(matches,plr)
table.insert(table.find(matches, plr), val)

You can’t access LocalPlayer in a server script, change that to local script and put it inside StarterGui or anywhere the local script can run
The script isn’t correct, change line 7 to table.insert(table[plr], val)

Yea right my bad, I forgot I’m sorry.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.