Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Item not found in tool, returning error?

Asked by 6 years ago

I have this script, which is supposed to make the cheese visible in the tool. The cheese is not in a model within the tool, it's just in the tool. The script is as follows:

script.Parent.Touched:connect(function(h)
if (h.Parent.Name == "Bread" or "Sandwich") then
        h.Parent.Name = "Sandwich"
        h.Parent.cheese.Transparency = 0
        h.Parent.cheese.Value.Value = 1
end
end)

It returns the error, "cheese is not a valid member of model"

What could have went wrong?

0
Make sure capitalization is correct for cheese since Lua is case-sensitive. If that doesn't work, declare it is a variable using "local cheese = h.Parent:WaitForChild("cheese")" Loughdough 291 — 6y
0
The case sensitivity is correct, and the variable just returns the error "infinite yield possible" and does nothing. Prideful_Ryan 38 — 6y

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
6 years ago

When defining compound conditions, even if there is a mutual value between the conditions, you must compare it each time.

script.Parent.Touched:connect(function(h)
    local hp = h.Parent;
    local name = hp.Name;
    if name == "Bread" or name == "Sandwich" then --compare name twice
        hp.Name = "Sandwich"
        hp.cheese.Transparency = 0
        hp.cheese.Value.Value = 1
    end
end)

Also, I suggest using the Disconnect function if you don't plan on manipulating the Name, Transparency, or cheese further. So that the Touched event isn't redundantly firing.

0
Still didn't seem to work for me. I'm not sure why, it doesn't show any errors, it just doesn't make the cheese brick appear. Prideful_Ryan 38 — 6y
Ad

Answer this question