So this is a problem that i encountered a few weeks ago and cannot find any fix to it. Whenever i try this specific for loop, theres a huge delay in server. For example, whenever i walk on client, its really really delayed on server and it looks like im lagging on other player's screen.

Heres the script:

LocalScript:

local function getobjects()
    return game:GetDescendants()
end

for i,v in next, getobjects() do
    v.Changed:Connect(function(p)
        game:GetService("ReplicatedStorage").Prop:FireServer(v, tostring(p), v[p])
    end)
end

Remote Script:

local PropRemote = game:GetService("ReplicatedStorage"):FindFirstChild("Prop", true) or false


PropRemote.OnServerEvent:Connect(function(plr, part, prop, value)
	wait()
	part[prop] = value
end)

If you know how to fix this problem, please let me know. Ive been trying for 3 weeks now and i cant find any way to fix it.

5 comments

0

A wait in your for loop would work

0

Yes but i want the loop to finish instantly

0

A normal Wait() would be very quick. I heard it's 1 or 10 milliseconds; I'm not sure; if that's true, then the naked eye wouldn't be able to notice it.

0

no its 1/30 fraction of a second.

0

The reason this has so much of a delay is not because wait() takes so long, it's because your script is completely inefficient. Event connections take up system resources, and you're creating one for every object in the game. On top of that, you're introducing unnecessary network delay by using RemoteEvents for literally no reason at all