How do I correctly check if a string value in ServerStorage is clear/empty?

What do I want to achieve?

I wish to achieve for my script to check a string value in ServerStorage, then edit the text labels color according to if it’s clear/empty.


What is the issue?

I keep getting this error:
image
I’m very confused as to why this keeps happening whenever the value gets changed.

When I click on this error, it returns me to this line:

if room.Value ~= "" then
script.Parent.BackgroundColor3 = Color3.fromRBG(255, 0, 0)  -- returns me here
end

Full code:


while true do
	
	local room = game.ServerStorage.Normal_Rooms:FindFirstChild(script.Parent.Name)

	
	if room.Value == "" then
		script.Parent.BackgroundColor3 = Color3.fromRGB(0, 255, 8)
	end	
	
	if room.Value ~= "" then
		script.Parent.BackgroundColor3 = Color3.fromRBG(255, 0, 0)
	end
	
	wait(.5)
end

What solutions have you tried so far?

I originally had local room = ... out of the while true do loop, thinking the value may need re-read or something along those lines. But I still have the same error. I’ve looked up information on ServerStorage and I still can’t find the correct solution.


Script Location:

Value Location:

I put the locations here, as I’m unsure if how I have this set up may just be the problem.

You’ve got a minor typo.

Color3.fromRGB(255, 0, 0)
1 Like

FindFirstChild() returns nil if it can’t find anything. So in your case, if a room isn’t found then your room variable will be set to nil. So the reason you’re getting that error is that you’re essentially checking nil.Value in your if statements (which you can’t do). So to fix this I’d suggest changing your if statements to check if room == nil or room ~= nil depending on what you want to happen.

1 Like