Printing value gives out none as output

Basically, this is a part of my code that checks the player’s loadout. When a change is detected (I didn’t put it here) it automatically changes a boolvalue to true. However, when I print out the value of the loadout’s values, it outputs nothing, even if there is a value.

if player:WaitForChild("Loadout") then
	print("loadout")
	-- Loading
	for i, v in pairs(player:WaitForChild("Loadout"):GetChildren()) do
		if v:IsA("StringValue") then
			print(v.Name)
			print(v.Value)
		end
	end
end

Probably should put it in, as too have a complete script.

What exactly do you mean by checking the player’s loadout? Are you checking if their character is fully loaded, because if so, it’s better to use Player.CharacterAppearanceLoaded or Player:CharacterAdded()

The folder for the loadout is inside the player itself, not the character

image

Although the datastore doesn’t work in studio it also doesn’t work in roblox


(Debug compared to print)

Ok now i’m understanding more of the situation.

Ok, from what I can see in the script, i’m not seeing specific variable’s, like the variable calling for the player.

local Player = game:GetService("Players").LocalPlayer

Make sure this script, is a local script, inside StarterGui,StarterPlayer or StarterPack (StarterPlayer recommended)

Also I find the WaitForChild() a little redundant, perhaps use a variable instead. So the script would look a little like:

local Player = game:GetService("Players").LocalPlayer
local Loadout = Player.Loadout

for i,v in pairs(Loadout:GetChildren()) do
   if v:IsA("StringValue") -- if the only thing in that folder is just string value's, this if statement is unnecessary
      print(v.Name)
      print(v.Value)
   end
end

Let me know if it doesn’t work.

PS: Put the script in StarterPlayer > StarterPlayerScripts instead of StarterCharacterScripts

The script is inside of startergui, since it is the handler for my menu.

Every variable has been placed already.

I’ve gone ahead and removed the wait for child but it still returns none.

I’ll probably use remote events to send the data to the client since this ain’t working. It’s just that I use datastore2 and I’m still learning it.

UPDATE: Im now using remote events to send the data, but thanks for helping though!

1 Like

try do this:

if player:WaitForChild("Loadout") then
	print("loadout")
	-- Loading
	for i, v in pairs(player:WaitForChild("Loadout"):GetChildren()) do
		if v:IsA("StringValue") then
			print(v.Name)
			print(tostring(v.Value)) -- it convert the value (boolean, number, etc) to string, if want u can do in the same line like print(v.Name.. " - ".. tostring(v.Value))
		end
	end
end

did you set value by local script? it cant read by normal script…

Values are all server-sided to cut down the risk of exploiting.