因此,我创建了一个按钮脚本,当单击该按钮时,如果满足特定条件,它将找到不同模型的所有子代,但是当我找到这些子代时,它给我一个错误,指出“ Obj不是有效的模型成员”,然后什么也不做
这是我的代码:
script.Parent.Touched:Connect(function(hit)
if(hit.Name == "RightFoot" or hit.Name == "LeftFoot") then
if(script.Parent.Color == Color3.fromRGB(0, 255, 0)) then
--This line is where im getting problems, when i do this :GetChildren
for _, object in pairs(script.Parent.Parent.Obj:GetChildren()) do
if(object:IsA("BasePart")) then
object.CanCollide = true
object.Transparency = 0
end
end
end
end
end)
答案 0 :(得分:-1)
<something> is not a valid member of model
是您尝试访问不存在的值时遇到的错误。因此,无论script.Parent.Parent
是什么,它都没有名为Obj
的孩子。
我建议不要从可靠的地方使用绝对路径,而不要使用诸如script.Parent.Parent之类的相对路径导航到对象。像...
local button = script.Parent
button.Touched:Connect(function(hit)
if(hit.Name == "RightFoot" or hit.Name == "LeftFoot") then
-- find the model you are looking for
local targetModel = game.workspace:FindFirstChild("Obj", true)
if not targetModel then
warn("could not find Obj in the workspace, try looking somewhere else")
return
end
-- if the button is green, make stuff invisible
if(button.Color == Color3.fromRGB(0, 255, 0)) then
for _, object in pairs(targetModel:GetChildren()) do
if(object:IsA("BasePart")) then
object.CanCollide = true
object.Transparency = 0
end
end
end
end
结束)