Script cant find value in ServerStorage

Im creating script that will lock server so no-one can join it.
But it throws an error: locked is not a valid member of Folder “ServerStorage.Settings”
So i added print statement:

cfg = game.ServerStorage.Settings

for i, value in cfg:GetChildren() do
	print(i, ": ", value)
end

And it outputs:
14:27:11.959 1 : ps - Server - handleEvent:12
14:27:11.962 2 : locked - Server - handleEvent:12
14:27:11.962 3 : version - Server - handleEvent:12

ServerStorage screenshot:
image

Edit: even roblox autocomplete gives me this:
image

Try this

cfg = game.ServerStorage:WaitForChild("Settings")

for i, value in cfg:GetChildren() do
	print(i, ": ", value)
end

I’m not 100% sure if it’d work, but give it a shot.

Also, to mention it worked before in other script where i used commands instead of gui, when i deleted and put it into gui it stopped working and after i got it back to commands it still didnt work

1 Like

Didnt work either, but it would change nothing because it was already getting instance and not throwing error about Settings is nil (output is still same)

1 Like

Where is the “roblox autocomplete” script located, and have you checked if it even exists from that script?

You should also use local ServerStorage = game:GetService("ServerStorage") instead of game.ServerStorage.

By roblox autocomplete i mean that it gives me ‘locked’ as child of Settings meaning im not blind idiot and it actually exists (like if i created function it will showup in this gui to help me and so i could tab to auto-complete it)

I dont know difference between game.child and game:GetService(), i mean one is method but both still return instance?

Even if it works in auto complete it’s still good to ENSURE it exists.

I’ve done some quick testing and gotten it to work:
image
image

Script:

local ServerStorage = game:GetService("ServerStorage")

local Settings = ServerStorage:WaitForChild("Settings")

for i, v in Settings:GetChildren() do
	if v:IsA("IntValue") then
		print(v.Value)
		v.Value = 2
		print(v.Value)
	elseif v:IsA("StringValue") then
		print(v.Value)
		v.Value = "wassup"
		print(v.Value)
	end
end

Is this something along the lines of what you want your script to do?

Edit: 5 and hello are the default values I set. 2 and wassup are the ones set in the script.

I know what you’ve done wrong.

You forgot to add .Value at the end of cfg.locked, so it’s trying to change the instance itself instead of the value.

Try cfg.locked.Value and it should work!

image

cfg = game:GetService("ServerStorage").Settings

for i, child in cfg:GetChildren() do
	print(i, ": ", child)
	if child:IsA("BoolValue") then
		child.Value = true
		print(i, ": ", child, ", ", child.Value)
	end
end

It exists for 100%, even kicks me when i join cuz locked is true lol:
Server Kick Message: This server is locked.

LMAO and interesting that:

if cfg.locked.Value == true and plr.UserId ~= ownerId then
	plr:Kick("This server is locked.")
end

Works and kicks me, located in adminCommands:
image

oh bruh, umm i think it will, umm lemme test :>

1 Like

That’s the same place the script used in my example was located so it should definitely work. If it exists then as I mentioned earlier try adding .Value to the end of cfg.locked.

Edit: This is a common mistake that I myself still do sometimes. Always remember to add .Value if you’re going to modify the Value property in value instances!

The most confusing that i hate rioblox engine throws error ‘invalid member’ cuz for me it seems like ‘locked’ instance doesnt exists but instead it tries to find property of folder

1 Like

It’s because when you do this the script thinks you’re trying to change the member locked in the folder, which of course isn’t a valid member:
image

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.