Help with an ongoing problem with Streaming enabled?

sometimes I need SE for games that are too laggy and need a performance boost.
but having streaming enabled ruins localscripts that need to access something in the workspace.

here is an example localscript that only works without SE:

local plr = game.Players.LocalPlayer

local char = plr.Character

while true do

wait()

local lobby = game.Workspace.Lobby

local firstlapcount = lobby.Spawn1.LapCount

local secondlapcount = lobby.Spawn2.LapCount

local thirdlapcount = lobby.Spawn3.LapCount

local fourthlapcount = lobby.Spawn4.LapCount

local fifthlapcount = lobby.Spawn5.LapCount

local sixthlapcount = lobby.Spawn6.LapCount

local firstowner = lobby.Spawn1.ClickerPart.CurrentOwner

local secondowner = lobby.Spawn2.ClickerPart.CurrentOwner

local thirdowner = lobby.Spawn3.ClickerPart.CurrentOwner

local fourthowner = lobby.Spawn4.ClickerPart.CurrentOwner

local fifthowner = lobby.Spawn5.ClickerPart.CurrentOwner

local sixthowner = lobby.Spawn6.ClickerPart.CurrentOwner

script.Parent.Text = “[”…firstowner.Value…“:”…firstlapcount.Value…“][”…secondowner.Value…“:”…secondlapcount.Value…“][”…thirdowner.Value…“:”…thirdlapcount.Value…“][”…fourthowner.Value…“:”…fourthlapcount.Value…“][”…fifthowner.Value…“:”…fifthlapcount.Value…“][”…sixthowner.Value…“:”…sixthlapcount.Value…“][”

end

with SE enabled, Clickerpart is not a valid member of the workspace.
on more than one occasion not even waitforchild solves this problem.
is there a way for me to force something to load so the client can see it when it needs to be seen?

Use :WaitForChild. It’s a caveat in SE for clients. All things replicated are slightly delayed.

They will be like: workspace:WaitForChild("Model"):WaitForChild("Part"), if the hierarchy goes in multiple scopes.

as I stated before, waitforchild does not work, it throws an infinite yield.

StreamingEnabled doesn’t give you control, the only way to fix that is :WaitForChild() and you still have to consider that :WaitForChild() will only unyield once the instance starts to exist, and that is not going to happen if the player isn’t close enough to the part to get in workspace.

This is confirmed by the documentation of Streaming Enabled.

(Quote is found at: Workspace | Documentation - Roblox Creator Hub)

1 Like

also, please write your code like this:

print("Hello World")

Perhaps the replication could not read the part at all or simply something is not properly done.

Reformat of the script:


Seriously, you gotta know how to do this.

-- On a side note of this, there could be loops, but I don't really know the way to implement them. Perhaps a table. 
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character

while wait() do -- what the hell
    local lobby = workspace:WaitForChild("Lobby")
    local firstlapcount = lobby:WaitForChild("Spawn1").LapCount
    local secondlapcount = lobby:WaitForChild("Spawn2").LapCount
    local thirdlapcount = lobby:WaitForChild("Spawn3").LapCount
    local fourthlapcount = lobby:WaitForChild("Spawn4").LapCount
    local fifthlapcount = lobby:WaitForChild("Spawn5").LapCount
    local sixthlapcount = lobby:WaitForChild("Spawn6").LapCount

    local firstowner = lobby:WaitForChild("Spawn1"):WaitForChild("ClickerPart").CurrentOwner
    local secondowner = lobby:WaitForChild("Spawn2"):WaitForChild("ClickerPart").CurrentOwner
    local thirdowner = lobby:WaitForChild("Spawn3"):WaitForChild("ClickerPart").CurrentOwner
    local fourthowner = lobby:WaitForChild("Spawn4"):WaitForChild("ClickerPart").CurrentOwner
    local fifthowner = lobby:WaitForChild("Spawn5"):WaitForChild("ClickerPart").CurrentOwner
    local sixthowner = lobby:WaitForChild("Spawn6"):WaitForChild("ClickerPart").CurrentOwner

    script.Parent.Text = "["...firstowner.Value...":"...firstlapcount.Value..."]["...secondowner.Value...":"...secondlapcount.Value..."]["...thirdowner.Value...":"...thirdlapcount.Value..."]["...fourthowner.Value...":"...fourthlapcount.Value..."]["...fsixthowner.Value...":"...sixthlapcount.Value..."]"
end

Looks like it’s time to hit the while true idiom thing.

Honestly, there could be better practices with remotes to change these values. Fire a remote to all clients whenever the lap count of any of the counters changes.

2 Likes

I guess I will have to go with this method for now :confused:

More than just. This code looks like a nightmare to read and maintain. I’m sure that this can be condensed into a function of sorts that can be reused several times over (whether hard coded or in an iterative loop), but by God should this be avoided in a production environment.

-- Lazy example: it's 1:28 AM and I'm trying to do things.

local lapStrings = {}

local function getLapHolderString(lap) -- Or whatever
    local lapCount = somethingRelatedToVariable
    local lapOwner = seeAboveNameThing

    return string.format("[%s:%s]", lapCount, lapOwner) -- Both need to be strings
end

for something [, orTheOther] in [iterator thing... next or pairs] do
    table.insert(lapStrings, getLapHolderString(oneOfTheVariablesAbove))
end

print(table.concat(lapStrings)) -- Did I desecrate Lua?

Above is an example but nothing definitive. Feel free to provide better code.

1 Like