Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make a for loop without server delay?

Asked by 3 years ago

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.

0
A wait in your for loop would work MarkedTomato 810 — 3y
0
Yes but i want the loop to finish instantly RemsFriend -24 — 3y
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. LazokkYT 117 — 3y
0
no its 1/30 fraction of a second. RemsFriend -24 — 3y
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 OfficerBrah 494 — 3y

Answer this question