GetDescendants not working in a LocalScript

For some reason, printing :GetDescendants is not printing everything, it works like :GetChildren.

for i,v in ipairs(workspace:GetDescendants()) do
	print(v)
end

Where is this LocalScript located?

Workspace. Its a script with the RunContext to Client.

Try putting it in StarterPlayerScripts.

Doesn’t work. I figured out that you have to add a wait because it doesn’t load when the player joins.

Could we perhaps get the context of why you’re using :GetDescendents() for? We might be able to help you from there.

Trying to make a crash script:

task.wait(5)
local Cars = workspace:WaitForChild("Cars")

local function breakWeld(part)
	local weld = part:FindFirstChildWhichIsA("WeldConstraint")

	if weld then
		weld:Destroy()
	end
end

for i,v in ipairs(Cars:GetDescendants()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			local speed = (v.AssemblyLinearVelocity - hit.AssemblyLinearVelocity).Magnitude

			if speed >= 20 then
				breakWeld(v)
			end
		end)
	end
end
1 Like

try use RemoteEvent?
server sends array, and you just get in local script

Yeah but I don’t think thats efficient.

1 Like

dude thank you!! i couldnt figure out why it wasn’t working

Its a localscript, It’ll print everything THAT IS LOADED not everything that is there. Maybe after game:Loaded it will have everything.

I don’t recommend having a local script in workspace. Due to it only being able to interpret objects that are loaded for the client. Either move the script to starterplayerscripts or switch to server-side script.

It could be the ipairs. Try removing it maybe?

thats because then it wouldnt work. i also think he shouldve used a local script and wait for the game to load, but we are late 10 months

You could always just make it a server-side script, and if the local script is really necessary remote events could be used I guess. But yeah, I presume we’re already too late.

add things in the workspace so this code actually does something,

maybe add a decal inside the baseplate, and inside that a humanoid, and inside that a texture, and so on…

Thanks but I have already solved it. You just have to wait until the object gets added.

model.ChildAdded:Connect(function(child)
-- stuff
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.