Hello, i want my code to scan the childs of a folder to see if the child of that folder has a child named “Something”. So then it can do something to that supposed “GrandChild?”. but i dont know how.
i have 10 plots and i want to check if each of those plots have a part/model in it so that it can turn its transparency and cancollide to 0 and true.
here is my local script code:
script.Parent.SelectPlotFrame.Visible = false
local plots = workspace.Plots
local plotButton = script.Parent:WaitForChild("PlotButton")
local selectingPlot = false
local camera = workspace.CurrentCamera
plotButton.MouseButton1Click:Connect(function()
local ownedPlot = nil
for i, plot in pairs(plots:GetChildren()) do
if tonumber(plot.Owner.Value) == game.Players.LocalPlayer.UserId then
ownedPlot = plot
end
end
if ownedPlot then
game.ReplicatedStorage.PlotSystemRE:FireServer("removePlot")
plotButton.Text = "PLOTS"
selectingPlot = false
script.Parent.SelectPlotFrame.Visible = false
else
selectingPlot = not selectingPlot
if selectingPlot then
camera.CameraType = Enum.CameraType.Scriptable
local plotsToSelect = {}
for i, plot in pairs(plots:GetChildren()) do
if plot.Owner.Value == "" then
table.insert(plotsToSelect, plot)
end
end
local currentPlot = 1
script.Parent.SelectPlotFrame.PlotName.Text = plotsToSelect[currentPlot].Name
camera.CFrame = CFrame.new(plotsToSelect[currentPlot].Position + Vector3.new(0, 70, 0) + plotsToSelect[currentPlot].CFrame.LookVector * 50, plotsToSelect[currentPlot].Position)
script.Parent.SelectPlotFrame.LeftArrow.MouseButton1Click:Connect(function()
currentPlot -= 1
if currentPlot == 0 then currentPlot = #plotsToSelect end
script.Parent.SelectPlotFrame.PlotName.Text = plotsToSelect[currentPlot].Name
camera.CFrame = CFrame.new(plotsToSelect[currentPlot].Position + Vector3.new(0, 70, 0) + plotsToSelect[currentPlot].CFrame.LookVector * 50, plotsToSelect[currentPlot].Position)
end)
script.Parent.SelectPlotFrame.RightArrow.MouseButton1Click:Connect(function()
currentPlot += 1
if currentPlot == #plotsToSelect + 1 then currentPlot = 1 end
script.Parent.SelectPlotFrame.PlotName.Text = plotsToSelect[currentPlot].Name
camera.CFrame = CFrame.new(plotsToSelect[currentPlot].Position + Vector3.new(0, 70, 0) + plotsToSelect[currentPlot].CFrame.LookVector * 50, plotsToSelect[currentPlot].Position)
end)
script.Parent.SelectPlotFrame.Visible = true
else
camera.CameraType = Enum.CameraType.Custom
script.Parent.SelectPlotFrame.Visible = false
end
end
end)
script.Parent.SelectPlotFrame.SelectPlotButton.MouseButton1Click:Connect(function()
game.ReplicatedStorage.PlotSystemRE:FireServer("buyPlot", script.Parent.SelectPlotFrame.PlotName.Text)
end)
game.ReplicatedStorage.PlotSystemRE.OnClientEvent:Connect(function(instruction)
plotButton.Text = "P"
selectingPlot = false
camera.CameraType = Enum.CameraType.Custom
script.Parent.SelectPlotFrame.Visible = false
script.Parent.Enabled = false
end)
my second normal script:
local plots = workspace:WaitForChild("Plots")
for i, plot in pairs(plots:GetChildren()) do
local ownerValue = Instance.new("StringValue", plot)
ownerValue.Name = "Owner"
end
local re = game.ReplicatedStorage:WaitForChild("PlotSystemRE")
re.OnServerEvent:Connect(function(plr, instruction, plotName)
if instruction == "removePlot" then
local playerPlot = nil
for i, plot in pairs(plots:GetChildren()) do
if tonumber(plot.Owner.Value) == plr.UserId then
playerPlot = plot
end
end
if playerPlot then
playerPlot.Owner.Value = ""
end
elseif instruction == "buyPlot" then
if plots:FindFirstChild(plotName) and plots[plotName].Owner.Value == "" then
plots[plotName].Owner.Value = plr.UserId
re:FireClient(plr)
plr.Character.HumanoidRootPart.CFrame = plots[plotName].CFrame + Vector3.new(0, 10, 0)
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
for i, plot in pairs(plots:GetChildren()) do
if tonumber(plot.Owner.Value) == plr.UserId then
plot.Owner.Value = ""
end
end
end)
here is a picture: