'SetBodyGroup' (a nil value)

Hey all,

Just got a problem with a little script I am working on, All I want it to do is if a player has armour then set its bodygroup.

Here is the code:
[lua]
function Armour( )
for k, v in pairs( player.GetAll() ) do
if v:Armor() >= 1 then
v:SetBodyGroup( 1, 1 )
v:SetNWBool(“Armour”, true)
end end end
hook.Add( “Think”, “Armour”, Armour )
[/lua]

If anyone can point me in the right direction it will be much appreciated.

Wait, I’m stupid. It’s a lowercase G in the function.

Entity:SetBodygroup( )

Well that seemed to have worked, Very strange bug, Thanks for the help Blackops and Kogitsune :slight_smile:

Not bug if you’re the one who typo’d

Sorry I am back with a similar error:

[lua]

function Armour( )

for k, v in pairs( player.GetAll() ) do

local body = v:GetBodygroup()

if v:Armor() >= 1 then

v:SetBodygroup( 1, 1 )

v:SetNWBool("Armour", true)

return end

if v:Armor() == 0 then
    if (v:GetBodygroup( 1 ) == 1) then

        v:SetBodygroup( 0, 1 )



return end

end
end
end
hook.Add( “Think”, “Armour”, Armour )

[/lua]

This time it has no error at all and wont set it back to the default 0 bodygroup?

Any ideas?

SetBodyGroup

Sorry Salt that cant be the error, because you need to have it lower G.

SetBodygroup( slot, value )

So SetBodygroup( 1, 0 )

That worked perfectly Thanks! My only problem that I have been trying to figure out, is why does it only affect me and not the other players? Yet other players can see me with the new bodygroup?

Here is my code:

[lua]

function Armour( )

for k, v in pairs( player.GetAll() ) do

local body = v:GetBodygroup()

if v:Armor() >= 1 then

v:SetBodygroup( 1, 1 )

v:SetBodygroup( 2, 1 )

v:SetNWBool("Armour", true)

return end

if v:Armor() == 0 then
v:SetBodygroup( 1, 0 )

return end

end
end
hook.Add( “Think”, “Armour”, Armour )

function RemoveArmour( )

for k, v in pairs( player.GetAll() ) do

v:SetArmor(100)

end
end
concommand.Add( “RemoveArmour”, RemoveArmour )

[/lua]

You need to set the bodygroup on both the client and the server I think.

Hmmm any idea how I could do that?

Problem Solved!