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?
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.