• attempt to call method 'Team' (a nil value)
    27 replies, posted
local ply = LocalPlayer() if ply:Team() == TEAM_GCITIZEN then     local colTrail = Color(237, 59, 59)     if ply:Health() == 100 then         return true     else         ply.trailline = util.SpriteTrail(pPlayer, 0, colTrail, false, 100, 0, 1, 0.02, "trails/plasma.vmt")     end     local function gdeathtrail(ply)         SafeRemoveEntity(trailline)     end     hook.Add( "PlayerDeath", "gtraildelete", gdeathtrail ) end Why cmd says: attempt to call method 'Team' (a nil value) I use my code on client side
at a guess it would seem that the entity you're calling Team() on is nil or not a player, however that code looks fine to me. I'm also assuming that the line number that errors is this line? if ply:Team() == TEAM_GCITIZEN then if in doubt, add this line: print (LocalPlayer(), ply, LocalPlayer():Team(), ply:Team()) add if before your if statement
Yeah i have error at line 2. I added print and it didn't show me
wait, is that the whole file? you need to contain this inside a function and call it with a hook of some sort if you just put it at the root of the file it will run once (and by the sound of it too early)
local ply = LocalPlayer() local function gtrail()     if ply:Team() == TEAM_GCITIZEN then         print (LocalPlayer(), ply, LocalPlayer():Team(), ply:Team())         local colTrail = Color(237, 59, 59)         local trailline         if ply:Health() == 100 then             return true         else             ply.trailline = util.SpriteTrail(pPlayer, 0, colTrail, false, 100, 0, 1, 0.02, "trails/plasma.vmt")         end         local function gdeathtrail(ply)             SafeRemoveEntity(trailline)         end         hook.Add( "PlayerDeath", "gtraildelete", gdeathtrail )     end end Alright. I put function but my code doesn't work.
You have to put the whole thing in a hook. Also, trailline isn't defined - only ply.trailline is.
Is this for DarkRP? As you should use ply:getDarkRPVar("job") == TEAM_GCITIZEN.
Which HOOK i should use if i want to check if ply:getDarkRPVar("job") == TEAM_GCITIZEN
just use LocalPlayer() every time, don't try to store it in a variable. There is no meaningful performance loss.
The code still doesn't work function gtrail()     if LocalPlayer:getDarkRPVar("job") == TEAM_GCITIZEN then         print (LocalPlayer(), LocalPlayer, LocalPlayer():Team(), LocalPlayer:Team())         local colTrail = Color(237, 59, 59)         local trailline         if LocalPlayer:Health() == 100 then             return true         else             LocalPlayer.trailline = util.SpriteTrail(pPlayer, 0, colTrail, false, 100, 0, 1, 0.02, "trails/plasma.vmt")         end     end end local function gdeathtrail(LocalPlayer)     SafeRemoveEntity(trailline) end hook.Add( "PlayerDeath", "gtraildelete", gdeathtrail )
you never added a hook for gtrail
Which hook for gtrail i should use?
Dunno, I have no idea what you even want to do. It doesn't sound like even you know what you want to do.
=)) I want to make a trail and if i have less than 100 hp i must to see trail but if i have 100 hp i mustn't to see trail
Well I don't know. You should go to the Garry's Mod Wiki and figure it out for yourself.
Hmmm... i want to check my function everytime
There is a lot of different ways you can do this, but you should probably start by Removing LocalPlayer() as it's nil, the reason it's nil is because all of this is serversided and LocalPlayer() does not exist here. After this you might ask yourself(or us), "well how do i do this, how do i player?" and the answer to that is hooks. The hooks that this might be suited for can be EntityTakeDamage, Tick, etc.
EntityTakeDamage works if ply takes damage but if i will heal ply? Will it works?
There isn't a specific hook that gets called after a player is healed, you could make your own hook by detouring sethealth or something, or you can loop through all players every x second in a Tick hook and see if their health is 100, probably requires some other codes as well to make sure SpriteTrail is only called when its needed and not every tick but it should work.
Basically, you need to find your own way to use a combination or even just Think hook if you must. Some ideas local shouldTrail = false -- A little later, when the player is hurt or gains health... shouldTrail = (ply:Health() < 100)
attempt to call field 'SpriteTrail' (a nil value) If i add if !SERVER then return end My code doesn't work (Doesn't show print("job")) local ply = LocalPlayer() local function gtrail()         if LocalPlayer():Team() == TEAM_GCITIZEN then         local colTrail = Color(237, 59, 59)         local trailline         if   ply:Health() == 100 then             return true         else               ply.trailline = util.SpriteTrail(pPlayer, 0, colTrail, false, 100, 0, 1, 0.02, "trails/plasma.vmt")         end     else         print("job")     end end hook.Add( "Think", "checkevtime", gtrail ) local function spawni(ply)     if !SERVER then return end     if  ply:Team() == "TEAM_GCITIZEN" then         SafeRemoveEntity(trailline)     end end hook.Add( "PlayerSpawn", "some_unique_name", spawni ) function gdeathtrail( ply)     if !SERVER then return end     if  ply:Team() == "TEAM_GCITIZEN" then         SafeRemoveEntity(trailline)     end end hook.Add( "PlayerDeath", "gtraildelete", gdeathtrail )
util.SpriteTrail is not a client-side function.
If i put my code on the server side My code doesn't work (Doesn't show print("job"))
if !SERVER then Puts it on client. So does this if CLIENT then If you want to put it on server if SERVER then But I assumed you wanted it on client, since you use LocalPlayer(). If you want it on server, you will have to loop through all players. local function gtrail() for k,ply in pairs(player.GetAll()) do if ply:Team() == TEAM_GCITIZEN then local colTrail = Color(237, 59, 59) local trailline if ply:Health() == 100 then return true else ply.trailline = util.SpriteTrail(ply, 0, colTrail, false, 100, 0, 1, 0.02, "trails/plasma.vmt") end else print("job") end end end Also you are making a new util.SpriteTrail() every time which is going to eat up performance. And... SafeRemoveEntity(trailline) This should make errors SafeRemoveEntity(ply.trailline)
Uffff.... i want to use util.SpriteTrail (it works only on the server side) and i want to use LocalPlayer() (it is client side) and.... I'm stumped. What do i do... I put if CLIENT then but cmd says attempt to call field 'SpriteTrail' (a nil value).... local function gtrail()         if CLIENT then         if LocalPlayer():Team() == TEAM_GCITIZEN then             local colTrail = Color(237, 59, 59)             local trailline             if LocalPlayer():Health() == 100 then                 return true             else                   LocalPlayer().trailline = util.SpriteTrail(pPlayer, 0, colTrail, false, 100, 0, 1, 0.02, "trails/plasma.vmt")             end         else             print("job")         end     end     end hook.Add( "Think", "checkevtime", gtrail )
Instead of using LocalPlayer, loop through all players for _,ply in pairs(player.GetAll()) do
idk how to make it =(
Like I said up there -- SERVERSIDE local function gtrail() if SERVER then for k,ply in pairs(player.GetAll()) do if ply:Team() == TEAM_GCITIZEN then local colTrail = Color(237, 59, 59) local trailline if ply:Health() == 100 then return true else ply.trailline = util.SpriteTrail(ply, 0, colTrail, false, 100, 0, 1, 0.02, "trails/plasma.vmt") end else print("job") end end end end
Sorry, you need to Log In to post a reply to this thread.