Search code examples
luagarrys-mod

lua - garry's mod - attempt to call global 'Player' (a table value)


When trying start Garry's Mod server i get an error:

[ERROR] gamemodes/darkrp/gamemode/modules/base/sv_gamemode_functions.lua:227: attempt to call global 'Player' (a table value)

  1. unknown - gamemodes/darkrp/gamemode/modules/base/sv_gamemode_functions.lua:227

sv_gamemode_functions.lua:217-230

function GM:EntityRemoved(ent)

self.Sandbox.EntityRemoved(self, ent)
if ent:IsVehicle() then
    local found = ent:CPPIGetOwner()
    if IsValid(found) then
        found.Vehicles = found.Vehicles or 1
        found.Vehicles = found.Vehicles - 1
    end
end
local owner = ent.Getowning_ent and ent:Getowning_ent() or Player(ent.SID or 0)
if ent.DarkRPItem and IsValid(owner) then owner:removeCustomEntity(ent.DarkRPItem) end
if ent.isKeysOwnable and ent:isKeysOwnable() then ent:removeDoorData() end end

please help.


Solution

  • change this line

    local owner = ent.Getowning_ent and ent:Getowning_ent() or Player(ent.SID or 0)
    

    to

    local owner = ent :GetOwner()
    

    https://wiki.facepunch.com/gmod/Entity:GetOwner
    https://wiki.facepunch.com/gmod/Player:UserID