• ply attempt to index global. But the function is serverside
    8 replies, posted
Hello, I've not done gmod lua for couple of months so I might be missing something obvious. I'm creating a forcefield around an entity. For test I made it kill player in area but I cannot test it because I have the issue of ply attempting to index global. local IsForceFieldActivated = false; if SERVER then     function PART:Use()     local exterior = self.exterior         self:EmitSound( Sound( "doctorwho1200/coral/keyboard2.wav" ))         if(!IsForceFieldActivated) then             if(ents.FindInSphere(exterior:GetPos(), 30)) then                 ply:Kill()             end         end     end end
It's not defined anywhere in your code
I did local ply = LocalPlayer() Would it be outside or inside function?
Local player is nothing on the server side
What would I do to 'define' it?
Use the second argument of ENTITY/Use
Fixed it now. Now I got the forcefield to work but I need a way to disable if not in the area. I did this local IsForceFieldActivated = false; if SERVER then     function PART:Use(ply)     local exterior = self.exterior         self:EmitSound( Sound( "doctorwho1200/coral/keyboard2.wav" ))         if(!IsForceFieldActivated) then             if(ents.FindInSphere(exterior:GetPos(), 30)) then                 ply:GodEnable()             end         IsForceFieldActivated = true;         else         if(IsForceFieldActivated) then             self:EmitSound( Sound( "doctorwho1200/coral/keyboard2.wav" ))             ply:GodDisable()             IsForceFieldActivated = false;         end     end          function PART:Think(ply)         if(!ents.FindInSphere(exterior:GetPos(), 30)) then             ply:GodDisable()         end     end end end
Think doesn't have any arguments ents.FindInSphere returns a table, so your if check isn't going to do anything You should use the second argument of Use as per the wiki I would use a table to track who has god mode enabled from the sphere and use that to see if the player left the sphere.
Like this? local IsForceFieldActivated = false; if SERVER then     function PART:Use(ply)     local exterior = self.exterior         self:EmitSound( Sound( "doctorwho1200/coral/keyboard2.wav" ))         if(!IsForceFieldActivated) then             for k,v in pairs(ents.FindInSphere(exterior:GetPos(), 30)) do                 if(v:HasGodMode()) then                     v:GodEnable()                 else                     v:GodDisable()                 end             end         IsForceFieldActivated = true;         else         if(IsForceFieldActivated) then             self:EmitSound( Sound( "doctorwho1200/coral/keyboard2.wav" ))             ply:GodDisable()             IsForceFieldActivated = false;         end     end end end
Sorry, you need to Log In to post a reply to this thread.