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

In pairs loop running incorrectly?

I have a script that loops around a folder containing a bunch of seats. I have a BoolValueinside of each seat that changes to true when someone is sitting in the seat and changes to nil when no-one is sitting there. The players get moved to the seat when they click a part with a ClickDetector which gets sent to the client. The value changes on the server. The script is supposed to change the value to true but for some reason it just gives me the error:

22:24:26.407 - FILLED is not a valid member of Script

The server script I am using is in a folder in a part within a ClickDetector. It also prints 36 nil's right before the error.

local seat

script.Parent.MouseClick:Connect(function(plr)
	for i, v in pairs(workspace.TP:GetChildren()) do
		if v then
			if v.FILLED.Value == nil then -- error line
				v.FILLED.Value = true
				
				seat = v
				break
			else
				print(nil)
			end
		end
	end
end)

This code was in a LocalScript but it gave the same error. I am not looping around the script so I have no idea why this is happening. Could this be a Roblox glitch?

Thanks for the help!

9 comments

0

Are you sure that everything is spelt correctly? And take a look at line 7 ;)

0

Thanks for line 7!

0

lol

0

Still did not work though even after I changed the code

0

Updated the code on S-H

0

One of the children of TP may be a script. Try filtering it out by ClassName.

0

ok

0

WORKED! Thanks. Although I already checked if there were any scripts there and there were none. I don

0

't care it works!

1 answer

✓ Accepted answer

From what it looks like, something in TP does not have a BoolValue named "FILLED". You should check if an object named "FILLED" exists with the :FindFirstChild() method. Additionally, since it is a BoolValue, the value will never be nil. It will be false.

local seat

script.Parent.MouseClick:Connect(function(player)
    for _, v in ipairs(workspace.TP:GetChildren()) do
        if v:FindFirstChild("FILLED") and not v.FILLED.Value then -- no == nil, == false needed 
            v.FILLED.Value = true -- you forgot .Value here
            seat = v
            break
        else
            print("does not have 'FILLED' BoolValue:", v)
        end
    end
end)

Finally, that is not an "in pairs" loop. That is a generic for loop.


######Hopefully this answered your question, and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions, then feel free to leave them down in the comments.

3 comments

0

If this method works I will accept

1

Also can't believe I did the == nil thing!

0

This worked too!

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