【发布时间】:2021-12-28 23:00:01
【问题描述】:
local colorwheel = script.Parent
local clickdetector = colorwheel.ClickDetector
--- Left mouse click (turn on)
clickdetector.MouseClick:connect(function()
print("lights on")
for _,p in pairs(workspace.OceanVillagedr201:GetChildren()) do
if p.Name == ("Downstairs") then
for _,x in pairs(p:GetChildren()) do
if x.Name == "Kitchen Bar Counter" then
for _,d in pairs(x:GetChildren()) do
if d.Name == "barlight" then
for _,j in pairs(d:GetChildren()) do
if j.Name == "light" then
j.Transparency = 0
else
end
end
end
end
end
end
end
end
end)
--- Right mouse click (turn off)
clickdetector.RightMouseClick:connect(function()
print("lights off")
for _,p in pairs(workspace.OceanVillagedr201:GetChildren()) do
if p.Name == "Downstairs" then
for _,x in pairs(p:GetChildren()) do
if x.Name == "Kitchen Bar Counter" then
for _,d in pairs(x:GetChildren()) do
if d.Name == "barlight" then
for _,j in pairs(d:GetChildren()) do
if j.Name == "light" then
j.Transparency = 1
else
end
end
end
end
end
end
end
end
end)
此脚本负责在“色轮”检测到点击时打开和关闭灯。为了保持我的工作空间井井有条,我将模型放入模型中,然后将这些模型放入文件夹中,本质上为我要修改的原始对象创建了很多 .parents。如您所见,这导致我不得不调用 :GetChildren() 函数,因此我可以让脚本在所有 parents 中搜索单个对象。有没有办法简化这一点,或者这是否被认为是在 Roblox 上编写脚本的适当方式?
【问题讨论】: