Int Values question

Is it possible to create int values in a table or is there a better way of doing it? They would be parented to the player.
I want to create int values in a table so I can set different number values for each intvalue and player.
Or do I have to create multiple local variables do something with that?

I think you can make it by doing a math.floor or math.ceil thing.

No need for creating IntValues. You can just use variables.

You could make a table, where the keys are Player objects, and the values are tables that contain your numbers.

So the table would look something like this mid-game

data = {
  [game.Players.therobotninja123] = {
    SomeNumber = 10,
    AnotherOne = 50,
    -- ... etc
  },
  [game.Players.nicemike40] = {
    SomeNumber = 15,
    AnotherOne = -10,
    -- ... etc
  },
  -- ... other players
}

This lets you access the data for a player like

print(data[game.Players.nicemike40].SomeNumber) --> 15

This table is pretty easy to maintain. You create it once:

local data = {}

When a player joins, make an entry in data for the player with the default values:

game.Players.PlayerAdded:Connect(function(player)
  data[player] = {
    SomeNumber = 100,
    AnotherOne = 200,
    -- ... etc
  }
end)

When they leave, cleanup that entry (there’s a way to do this automatically with weak table keys, but this is simpler :slight_smile: ):

game.Players.PlayerRemoving:Connect(function(player)
  data[player] = nil
end)
2 Likes

Would the key basically parent the variable to the player? That’s the only reason why I’m using int values rn.

It’s not so much “parented”, but it is associated with that player, yes. See my example about accessing data for a player.

I get it. I’ll try it out and see if I can figure out some things myself because some things are better explained by finding it out than in words. Hopefully this will prove helpful and thanks for your answer.