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

Trying to detect if a value is or isnt inside of a part for a script but wont work?

What I want the script to do is see if ORDER is inside of v then it will run the rest but it gives me an error saying the ORDER is not a valid member of the script that is also in that group.

script.Parent.Changed:Connect(function()
	if script.Parent.Enabled == true then
for i,v in pairs(folder:GetChildren())do
	if v.ORDER ~= nil then
		if v.ORDER.Value == 1 then
			cam.CameraType = Enum.CameraType.Scriptable
			cam.CameraSubject = v
		end
	end
end
end
end)

1 answer

✓ Accepted answer

Use FindFirstChild(), so that it doesn't error when the part doesn't exist

script.Parent.Changed:Connect(function()
	if not script.Parent.Parent.Enabled then return end
	for i,v in pairs(folder:GetChildren()) do
		local order = v:FindFirstChild("ORDER") --here, see?
		if order and order.Value == 1 then --check if it exists and if its value == 1
			cam.CameraType = Enum.CameraType.Scriptable
			cam.CameraSubject = v
		end
	end
end)

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