Cannot get a "Costs" Value

Hello!
So I’ve been making a sell system and when the player sells. It will get a item costs and sell it
but apparently, the “Costs” Value doesnt exist which make me curious because the Costs value isnt a value that is being generated before BUT it was putted by order (which means the script didnt generate it).
Here is a quick example of what i meant:
image
This is the children of the gun that player will sell.
image
This is all of the instance children name (MP7 Orange is a player sellling item name)
(Uncommon is the rarity of the gun that the players want to sell)
As you can see. Theres no “Costs” or “RarityColor” located in the output.
However, when you rejoin and sell again. The costs and Raritycolor do exist.
This is the code I used to get the guns costs

				print("Item code value exist")
				print(itemcode.Value.Name)
				print(itemcode.Value.Parent.Name)
				for i,v in pairs(itemcode.Value:GetChildren()) do
					print(v)
				end
				local costs = itemcode.Value:FindFirstChild("Costs")

Is this a bug? or was it just an error of my script?

Also, the reason theres a value because i stored a objectvalue for saving located in the player.

I can only think of one problem with this. You’re printing all of its children before they are created. I believe there is a delay no matter how small before the children are created and parented within the script. So, before checking all of the children and printing them, I would say to wait a bit (assuming this is actually running immediately).

1 Like

I think it is not possible since the sell button (and other stuff) are preventing the player to sell immediately.Which takes about 3-6 seconds.

Alright, have you tried checking whether the values are archivable? If they are, make them not archivable as it can stop scripts from properly referencing them.

1 Like

Yes, I tried to check the Costs and the archivable is set to true

Also i forgot to tell. I used waitforchild and it said it cannot find the costs

So i make the archivable set to false?

Yes, make archivable set to false.

1 Like

It still cannot find the Costs value :frowning_face:

Actually, my bad, archivable is supposed to be set to true, but I have absolutely no idea what’s going on here. Are you creating the values through a local script?

Yes, it was passed on the local script and send to the server script by the remoteevent.

	if script.Parent.Parent.Item.Value then
		if script.Parent.Parent.Cooldown.Value <= 0 then
			
			print("Selling "..script.Parent.Parent.Item.Value.Name)	
			game.ReplicatedStorage:WaitForChild("SellEvent"):FireServer(script.Parent.Parent.Item.Value,"Sell imme")
		end		
	end

No, I meant were the values created on the client, or were they created on the server? If they were created on the client, the server can’t see those values.

I dont know how to explain this but I just open a properties bar and add a value

I just runned a debug by finding all instance that named “Costs” and here are the results:


It clearly proves that the costs do exist.

Well, that’s… Confusing. I have absolutely no idea what it could be if you are doing the same thing for others but it’s not working for one.

1 Like

Well i did the manual way. A bit difficult but gets the work done.

					for i,v in pairs(game.Lighting.CasesStuff:GetDescendants()) do
						if v.Name == "Costs" then
							if v.Parent.Name == itemcode.Value.Name then
								print("Costs found located on the "..v.Parent.Name)
								costs = v
								break
							end
						end
					end
local instance = game.Lighting.CasesStuff:FindFirstChild(intemcode.Value.Name, true)
if instance then
	local cost = instance:FindFirstChild("Costs")
	if cost then
		--Do code.
	end
end

You could use the recursive parameter of FindFirstChild() to conduct the search within the object’s descendants.

1 Like