just wrap the if statement inside the loop into a pcall, it avoids the issue (literally just remembered pcalls existed lol)
I started getting the “The current thread cannot access ‘StreamingService’ (lacking capability Assistant)” error today in code which I haven’t even touched in months.
It seems in the latest studio update they made game.StreamingService error out if you try to access anything in it, even doing print(game.StreamingService.Name)
will trigger this error. Sad as it’s easy to accidentally do in any run-once prep script which steps through game:GetDescendants().
alright after further debugging i found out streaming service is the 66th child of game, so checking if it’s the 66th iteration and skipping it when looping with ‘game:GetChildren()’ will avoid the error.
local _, success = pcall(function()
for i, v in pairs(game:GetChildren()) do
if i > 66 or i < 66 then
print(i, v)
end
end
end)
I am getting this issue in Studio as well with code that has been untouched. I think it’s a bug.
i have objects to clear from thing within other services aswell
tried that and it still dosent work
also note that this error only happens in studio, not in game. it just makes testing 10x harder
oh wait, try 65 then, as i have a folder in game, which made the total child count of game 107 instead of 106.
As @BendsSpace said, just wrap it in pcall. Because relying on this service number is not safe, if roblox adds another one the error will reappear.
module.ClearAttribute = function(plr)
pcall(function()
for i,v in pairs(game:GetDescendants()) do
if v:GetAttribute("Ownership") == plr.Name then --line 28
if v.Name ~= "dang" then
v:Destroy()
else
v:Destroy()
if not game.Lighting:FindFirstChild("dang") then
local sky = script.Sky:Clone()
sky.Parent = game.Lighting
game.Lighting.Brightness = 1
game.Lighting.Ambient = Color3.fromRGB(244,244,244)
end
end
end
end
end)
end
that may work, but i just used a pcall as someone suggest above
ex:
module.ClearAttribute = function(plr)
for i,v in pairs(game:GetDescendants()) do
local er,suc = pcall(function()
if v:GetAttribute("Ownership") == plr.Name then
if v.Name ~= "dang" then
v:Destroy()
else
v:Destroy()
if not game.Lighting:FindFirstChild("dang") then
local sky = script.Sky:Clone()
sky.Parent = game.Lighting
game.Lighting.Brightness = 1
game.Lighting.Ambient = Color3.fromRGB(244,244,244)
end
end
end
end)
end
end
ironic timing as i jsut used a pcall
yeah, though i found it errored at the 65th iteration even with the pcall, which is why i added the if statement.
This is a bug with the latest version of studio which is expected to be fixed in a week or so (see linked post), if you need a work around ASAP pcall is probably your only option for now.
using the pcall around the area where it loops the instances worked for me, not sure why it’d break
just make sure your using the pcall correctly around it
this is the post i was talking about in the post, glad its getting fixed soon
oops, i meant it just stops at the 65th iteration, not errors, i just wanted to loop through all the children in game without that silent error.
You probably resolved this already but for anyone looking for a shorter hotfix than pcall you can simply skip an item if it’s StreamingService itself.
for i, v in ipairs(game:GetChildren()) do
if v == game:GetService("StreamingService") then continue end -- Engine bug hotfix
-- (your code here)
end
oh thanks, i like this shorter version, it’ll keep my code clean.
This happened to me, it was because of the Animated Textures plugin. I uninstalled it and after that, everything was fine. No idea.
If you’re gonna do it like that, you may as well just not check every single thing in existance.
This will only check if the game’s children are StreamingService. So only about 110 instances rather than the 7000 I currently have in my game. And that’s a small one.
for _, service in ipairs(game:GetChildren()) do
if service == game.StreamingService then continue end
for _, descendant in ipairs(service) do
-- your code here
end
end
Also, the reason why this happens in the first place is because they changed the StreamingService’s properties and functions to only be accessible to the AI assistant.
So for example, when you loop over all descendants and check their ClassName it tries to check the StreamingService’s ClassName at some point.
Best regards,
Pinker