How would I make ascript 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.
