Reputation: 1
I've got an addon on my server that basically allows you to create territories. On top of that, I have one which allows you to make permanent properties, which players own even when they aren't online. Additionally, you are able to save the props inside these permanent buildings so that when you next get on, the props are all still there.
It was working fine, but I now seem to be encountering the following error whenever I save the props inside my house and restart the server. Also, a lot of the houses don't seem to work. But, when I unsave the props inside a house and restart, everything is back to normal.
The error
[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/territory/sh_init.lua:514: bad argument #1 to 'pairs' (table expected, got nil)
1. pairs - [C]:-1
2. LoadProps - addons/darkrpmodification-master/lua/darkrp_modules/territory/sh_init.lua:514
3. tsetUpDoors - addons/darkrpmodification-master/lua/darkrp_modules/territory/sv_init.lua:273
4. unknown - addons/darkrpmodification-master/lua/darkrp_modules/territory/sv_init.lua:290
Code
function BuyableTerritory:LoadProps(steamid, t)
for k, v in pairs(t) do
local e = ents.Create("prop_physics")
e:SetPos(v.pos)
e:SetAngles(v.ang)
e:SetModel(v.model)
if v.color then
e:SetColor(v.color)
end
if v.material then
e:SetMaterial(v.material)
end
e:Spawn()
e.permaOwner = steamid
e:GetPhysicsObject():EnableMotion(false)
end
local ply = DarkRP.findPlayer(steamid)
if IsValid(ply) then
self:SetPropsOwner(ply, ply:SteamID())
end
The code starts at line 513, so the second line in is the one having problems. Thank you.
Upvotes: 0
Views: 743
Reputation: 28994
Just read the error message. It tells you that the input to pairs() is nil instead of the expected table. pairs is a so called iterator. It only works with a Lua table as input.
Your input t
to BuyableTerritory:LoadProps(steamid, t)
is not valid.
You either have to change that or check if t
is a table befor you call pairs(t)
to prevent the error from happening.
Go to line 273 of sv_init.lua to find out whats going on.
Upvotes: 2