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:
This is the children of the gun that player will sell.
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).
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.
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.
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.