Will this cause lag?

I’m making a jojo game but the stands are lagging the game, I’m trying to find out whats causing lag, so i need to know if this is what causes it.

--server script
repeat wait() until script.Parent.Anchored == false
script.Parent:SetNetworkOwner(player)
while wait() do
    if script.Parent.Anchored == false then
    script.Parent:SetNetworkOwner(player) 
    end
end

if it does cause it, is there another way i can do this without any lag??

5 Likes

Can you show us the workspace so we can see the parts?

3 Likes

It wont cause any lag due to the nature of things causing lags are usually because it is using tons of recourses on the server/client.

1 Like

You could use the Script Performance tab and check the activity and rate there.
below 2-3% activity you’re good.

image

you don’t have to use SetNetworkOwner multiple times on the same part for the same player.
Make sure you have used it once on the right player. Don’t make an infinite loop to do this.

3 Likes

Yes it will cause “lag” (though not network-latency “lag”), because it is not optimal code. It looks like a “band-aid” for an issue that should not be there.

Why do you need to wait for the Anchored-property to become false?

The only thing that could change that Anchored-property, is your own script-code on the server.

So instead of that “anti-pattern” code you posted, it would be much better to change the network-owner where you also change the Anchored-property.

2 Likes

Use GetPropertyChangedSignal instead of an infinite loop, as it’s own purpose is to detect property changes.

2 Likes