Will using SetAttribute() a lot cause lag within a server?

Just theoretically, say I have a game in which every part that is spawned; (which will be on a while wait() do) loop, and those parts are to go down, and then first get an attribute of the name will be “Not an Apple” , true. Afterwards, the part will then get it’s attribute changed to “Apple”, true

Is that going to cause lag? Will it cause lag spikes? I haven’t really got any idea whether or not it will or won’t.

1 Like

Well, it’s pretty easy to test something like that; run the game and watch the performance in the developer console.

1 Like

No. In fact, they are technically faster than using Value objects (e.g. StringValue) at a CPU performance level. At a network level (replicating the changes from the server to the client), it is just a small piece of data. You won’t notice it at all.

Think about it this way: Every network update, the game is updating tons of moving parts from characters and having to interpolate them to make everything appear very smooth. That’s a lot of data moving in and out constantly! By simply changing an attribute from true to false, that’s just a small drop in the bucket.

That all being said, I would not set the attribute every frame if possible. Just set it when it actually needs to change.

1 Like

Isn’t it faster to use a table to change values in a module script rather than instances/attributes?

1 Like

Perhaps, but that won’t replicate to the client. If the goal is to communicate changes across all clients that are linked to specific instances, attributes are a safe solution

1 Like

Other advantages of using Attributes is there’s no property naming collisions (ever create a StringValue named “Name”"?) and they error out if they don’t exist. For example if part.StringValue will error if StringValue is not present on the part, but if part:GetAttribute("StringValue") will not error.

1 Like

Oh yeah, this is true since it’s not really it’s own instance which means it won’t error for not existing.