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

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

Asked by
Plieax 66
5 years ago

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

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
5 years ago

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

Answer this question