Error spam, code still works?

Hey, I’m running this code in a SWEP’s PrimaryAttack() function

[lua]
if !self.Owner:GetPData(“PerkInfiniteAmmo”) then
// Remove 1 bullet from our clip
self:TakePrimaryAmmo( 1 )
end
[/lua]
… and it spams this error message, every time you shoot the weapon

It still reads the PData, and it works well. However, I don’t want people to see the message spam. Is there a way to at least hide it, or is there a fix for it?

The server I am coding on is a dedicated server. Not singleplayer if that makes a difference.

Need more info. Also [“lua”] [/“lua”] tags without ".

The function
[lua]player.GetPData(string name)[/lua]
causes the error. I want to know if there is a way to hide the error from being shown, or if it’s even possible to fix it. On the wiki, it shows that it will always show an error clientside, but it’s really annoying to see the messages spam whenever someone shoots the weapon.

This line
[lua]if !self.Owner:GetPData(“PerkInfiniteAmmo”) then[/lua]
causes the error

What other info do you need?

GetPData()

Is a serverside function.

If used on the client it returns with that error. What you should do:

[lua]
if (SERVER) then
if !self.Owner:GetPData(“Ammo”)
– Code Here.
end
end
[/lua]

In the Garrysmod Wiki the function GetPData is a shared function, so it should work on both the client and the server shouldn’t it?
And I need this function, otherwise on the client’s side, the clip will go down when it is actually supposed to be one constant variable. The clientside clip should not change.

When I use the GetPData function on the client, the clip size will not change, however when it is not used, it will go down and then go back up to the server’s value. I do not want this to happen.

UniqueID is a server only function, so the code iRzilla posted should fix your problem by not calling a server function on the client. At least give it a try. :slight_smile:

Solved the problem!

Instead of using GetPData and SetPData, I used SetNetworkedBool and GetNetworkedBool.