GetDescendants()

Hello,
I have a script that must get the descendants of a folder in the workspace.
but the problem its that the script skip some descendants.

script.Parent.MouseButton1Click:Connect(function()
	print("click")
		wait(5)
	for _, v in pairs(game.Workspace.ToolModels:GetDescendants()) do
		print(v)
		if v:FindFirstChild("ClickDetetor") then
			print("find Detector")
			local clickScript = game.ReplicatedStorage:WaitForChild("Scripts"):FindFirstChild("Script"):Clone()
			clickScript.Parent = v.Parent
			clickScript.Disabled = false
		end
	end
end)

https://streamable.com/3oxmob

That’s the script in image.

This is the script that I want clone but it’s for later.
Screenshot (183)

1 Like

What do you mean? Which objects is it “ignoring”?

When you switch to server the gun disappears from the workspace. So that means that the gun is local. You must add the gun through the server (workspace, replicatedstorage, etc) to avoid this

2 Likes

its ignoring the Weapon model (PistolHandle)

It should be ClickDetector, not ClickDetetor:
bild

2 Likes

oh yes I didn’t see that let me fix it

I agree with @AvionicScript. I saw that when you changes to server side the gun doesn’t exists at all…

1 Like

Wouldn’t it be better to do

script.Parent.MouseButton1Click:Connect(function()
	print("click")
		wait(5)
	for _, v in pairs(game.Workspace.ToolModels:GetDescendants()) do
		print(v)
		if v:IsA("ClickDetector") then
			print("find Detector")
			local clickScript = game.ReplicatedStorage:WaitForChild("Scripts"):FindFirstChild("Script"):Clone()
			clickScript.Parent = v.Parent
			clickScript.Disabled = false
		end
	end
end)

because it’s looping through the descendants?

also, cloning server scripts from local scripts wouldn’t work because it’s a local change, the server wouldn’t see it and the code won’t run

1 Like

ok
but I cant do it to another way and if I clone the model from the Server everyone will see a lot of model at the same place

Well then you can do the GetDescendants on the client and use a remoteEvent to send the array to the server

1 Like

All Instances will be nil on server side if he do so.

2 Likes

Right I didn’t about that, then OP has no alternative besides adding the gun on the server

2 Likes

but the main problem that I switch to Script for clone the script(the script into ReplicatedStorage) that I want and not with a LocalScript, because when the script(the script into ReplicatedStorage) its cloned with a LocalScript its get broke (its don’t want work)
do you guys have a simple and fast solution for this?