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

How do I find a Part inside of a few Models?

How would I make a script to go into Models (with different names) and find a Part named "Head" inside them? And then turn them Transparency = 0?

local ting = 0	
owner = script.Parent.Parent.Parent.OwnerName

function onTouched(hit)

	if ting == 0 then -- debounce
		ting = 1 -- debounce
		local check = hit.Parent:FindFirstChild("Humanoid")

		if check ~= nil then -- debounce
			local user = game.Players:GetPlayerFromCharacter(hit.Parent)
			local cost1 = script.Parent.Cost
			local cost = user:FindFirstChild("leaderstats"):FindFirstChild("Dollars")
			local user = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			if (user:FindFirstChild("House") ~= nil) then 
			local user = game.Players:GetPlayerFromCharacter(hit.Parent)
			user.PlayerGui:FindFirstChild("AlreadyOwn").Frame.Visible = true

			elseif user:FindFirstChild("leaderstats").Dollars.Value >= cost1.Value then
				owner.Value = hit.Parent.Name
				cost.Value = cost.Value - cost1.Value	
				
-- the below should find "Head" inside of models of script.Parent.Parent.Parent and make them seen
					for i, v in pairs(script.Parent.Parent.Parent:GetChildren()) do
					if v:IsA("Model") then
					for ii, vv in pairs(v:GetChildren()) do
					if vv.Name == "Head" then
					vv.Transparency = 0
-- finding "Head" ends here

				local own = Instance.new("NumberValue")
				own.Name = "House"
				own.Parent = user
				own.Value = script.Parent.Sell.Value
				local ownshouse = Instance.new("NumberValue")
				ownshouse.Name = "OwnsHouse"
				ownshouse.Parent = user
				ownshouse.Value = script.Parent.Parent.Parent:FindFirstChild("Value").Value
				user.PlayerGui:FindFirstChild("HousePurchase").Frame.Visible = true
				script.Parent.Parent.Ad:remove()
				script.Parent.Parent:remove()
				local home = game.ServerStorage.Home2
				home.Parent = game.Workspace
		
			elseif user:FindFirstChild("leaderstats").Dollars.Value < cost1.Value then
				user.PlayerGui.NotEnough.Frame.Visible = true

			end
		end 


	ting = 0 -- debounce
	
	
	end 			end
					end
					end
					end


end

script.Parent.Touched:connect(onTouched)





This code errors:
Script:33: attempt to index field 'Parent' (a nil value) -- no idea why.

1 answer

Thats easy! Just use the FindFirstChild function

local Find = workspace.ModelNameHere:FindFirstChild("Head")
if Find then
  Find.Transparency = 0
end

1 comment

0

The "ModelNameHere" would have to be changed for all 101205930290 models I have. I want to avoid this by just going into all models no mater what their names are and looking for "Head"

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