I'm absolutely stumped here

-snip-

It has been resolved.

Okay, so I simplified the whole problem and now I’m almost pretty sure it’s a bug or something in GMod 13, because it makes no sense.

These are gamemode files:

init.lua
[lua]
AddCSLuaFile(“shared.lua”)
include(‘shared.lua’)

local DefaultData = {
Character = “Random”,
Color = “Gray”,
Coins = 0,
Effect = “none”,
Items = {}
}

function GM:PlayerInitialSpawn§
p.Data = DefaultData
end
[/lua]

shared.lua --Basically nothing
[lua]
GM.Name = “Test”
GM.Author = “SparkZ”
GM.Email = “N/A”
GM.Website = “N/A”

DeriveGamemode(“base”)
[/lua]

After loading the gamemode up, I spawn 3 bots.

Then I run this line of lua on the server:
[lua]
table.Merge(player.GetAll()[1].Data, {Coins = 50})
[/lua]

Instead of setting* just my *coin amount to 50, it sets all of the bots’ coin amounts to 50 as well.

So what do you guys think? Is this a bug or am I just going crazy?

bumped because i simplified it

try using player.GetByID(1).Data… instead of player.GetAll()[1].Data…

Same result :confused:

However, I just tested this on GMod12 and the problem was still present, so I don’t really think it’s a bug anymore.

Perhaps it has to do with the other 3 players being bots?

Oh, try defining the DefaultData inside the PlayerInitialSpawn hook, like:

[lua]

function GM:PlayerInitialSpawn§
local DefaultData = {
Character = “Random”,
Color = “Gray”,
Coins = 0,
Effect = “none”,
Items = {}
}

p.Data = DefaultData

end
[/lua]
and then the try the table.Merge(player.GetAll()[1].Data, {Coins = 50})

but I wouldn’t do it like that, I’d do:

[lua]

function GM:PlayerInitialSpawn§
p.Data = {
Character = “Random”,
Color = “Gray”,
Coins = 0,
Effect = “none”,
Items = {}
}

end
[/lua]

Mother of God, thank you… but why does it work that way and not how I had it?

[lua]p.Data[/lua]

This makes it Entity(Player in this case) specific

Well, its really simple…
Before, you had all the players(including bots) load their data from a preset table, that was DefaultData.
When you did table.Merge(player.GetAll()[1].Data, {Coins = 50}), you changed the DefaultData, thus changing ALL the Data tables from ALL the players, because the Data tables, are copies of the DefaultData.
By setting the DefaultData inside the InitialPlayerSpawn, you had a very different Data table to EVERY player, so when you did table.Merge(player.GetAll()[1].Data, {Coins = 50}), you set only the Data table of the first player of the table, and as the other players have their own Data saved to themselves instead of loading from a previously defined table, they remained the same.
Hope it was clear enough, its 3 AM here, a bit tired already.

Edit:

Yes and no, at his original code, he has a p.Data, but ALL the p.Data were retrieving their data from the same table, if you changed that table, you changed ALL the p.Data, making it not really player specific, but rather specific to the DefaultData table.

Okay, I think I understand now. I must have some misunderstandings of how some things like this work in lua.

For example, I’ve always thought that this:
[lua]
local GMData = {a = 5, b = “asdf”, c = true}

player.GetAll()[1].Data = GMData
[/lua]

Was exactly equal to this:
[lua]
function GetData()
return {a = 5, b = “asdf”, c = true}
end

player.GetAll()[1].Data = GetData()
[/lua]

Thanks for the help!