Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not Clearing Descendants Can I Get A Explanation?

Not sure what part has the issue so I'll just provide the entire script

game:GetService("RunService").RenderStepped:Connect(function()
	local Player = game.Players.LocalPlayer
	local View = script.Parent.ViewportFrame
	local CustomGeneratedName = math.random(4353245345324534534553434535,43532453453245345345534345354353245345324534534553434535)
	for i,v in pairs(View:GetDescendants()) do
		if v.Name == CustomGeneratedName then
			v:Destroy()
		end
	end
	local Cloned = script.TargetedObject.Value:Clone()
	Cloned.Parent = View
	Cloned.Name = CustomGeneratedName
	for i,v in pairs(Cloned:GetDescendants()) do
		if v then
			if not v:IsA("BasePart") and not v:IsA("Decal") and not v:IsA("Texture") and not v:IsA("SpecialMesh") then
				if v:IsA("Model") or v:IsA("Folder") then
					for i,v in pairs(v:GetDescendants()) do -- getting the descendants
						v.Name = CustomGeneratedName -- Setting the name
						v.Parent = View -- Setting the parent of the descendants of the cloned object
					end
				end
				v:Destroy() -- Destroying the descendants of the cloned object
			end
		end
	end

	if Player.Character then
		local Head = Player.Character.Head  -- Variable for the head
		if not Head:FindFirstChild("Camera") then -- Check's if there isn't a camera
			local NewCam = workspace.CurrentCamera:Clone() -- Creates a camera
			View.CurrentCamera = NewCam -- Set's the CurrentCamera
		end
		if Head:FindFirstChild("Camera") then
			local Cam = Head:FindFirstChild("Camera") -- Finds The Camera
			Cam.CFrame = Head.CFrame -- Sets the camera's CFrame  to the player's head
		end
	end
end)

If there is an issue with my script can someone correct it and explain the issue?

1 answer

✓ Accepted answer

I think the main problem is in line 15. Using "not" inside of if statements is wonky sometimes, so I would replace line 15 with this:

 if v:IsA("BasePart") or v:IsA("Decal") or v:IsA("Texture") or v:IsA("SpecialMesh") then
	wait()
else

1 comment

0

I would say it worked but this time i had another issue and i have no idea what it is But I'll accept this for now since it helped with the lag part

This discussion is preserved as it was. New answers, comments, and votes are closed.