Table doesn't print the values inside it

I’m working on a script that will detect if the player owns a specific item and print it.
For some reason, no results are appearing. The script is fired from a local script inside a button in StarterGui, to a server script in ServerScriptService.

Local script:

while true do
	wait()
	game.ReplicatedStorage.Events.Purchased.Detect:FireServer()
end

Server script:

game.ReplicatedStorage.Events.Purchased.Detect.OnServerEvent:Connect(function(Player)
	local Values = Player:WaitForChild("Values")
	local Units = Values:WaitForChild("Units")
	local RedCat = Units:WaitForChild("RedCat")
	local UnitsTable = {
		RedCat
	}
	for a, o in pairs (UnitsTable) do
		if o.Value == true then
			print(o.Value)
		end
	end
end)

Any help is appreciated!

1 Like

First of all, spamming that remote event will result into the remote event malfunctioning because it’ll exhaust because of the huge amount of requests.

Second of all, data in lists are only available when you do a number.

In your case:

	local Values = Player:WaitForChild("Values")
	local Units = Values:WaitForChild("Units")
	local RedCat = Units:WaitForChild("RedCat")
	local UnitsTable = {
		RedCat; -- [1]
        Units; -- [2]
        Values; -- [3]
	}

If you’d want to access them: You’d have to do this

UnitsTable[1] -- gets the RedCat value because that's the first data type
UnitsTable[2] -- gets the Units value because that's 2nd
UnitsTable[3] -- Get the 'values' value because its the 3rd
2 Likes