Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Item not found in tool, returning error?

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?

2 comments

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")"

0

The case sensitivity is correct, and the variable just returns the error "infinite yield possible" and does nothing.

1 answer

✓ Accepted answer

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.

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.