hello, im trying to make a system which allows you to sell in game valuables, which are stored in a folder in serverstorage.
on activation of a proximity prompt, i want it to get the children of the player’s data folder (which works,)
and also the for loop seems to work. i have put prints in several parts of the script since there are no errors, but the script does not function as intended.
(i haven’t used for loops before.)
prox = script.Parent
prox.Triggered:Connect(function(plr)
local data = game.ServerStorage.PlayerData[plr.Name]
local trinks = data:GetChildren()
print("1")
for i, v in pairs(trinks) do
print("1.5")
if v:FindFirstChild("Worth") then
print("2")
local moneytogive = v.Value
local ls = plr:FindFirstChild("leaderstats")
print("3")
local nw = ls:FindFirstChild("Net Worth")
local m = ls:FindFirstChild("Money")
m.Value = m.Value + v.Value
nw.Value = nw.Value + v.Value
print("4")
v:Destroy()
end
end
end)
the prints 1, and 1.5 do print, but the rest do not.
“Worth” is an IntValue inside of V which dictates how much money it sells for.
Instead of Print("1.5"), try Print(v, v:FindFirstChild("Worth")) instead to check if the Worth instance is not nil and if it is, which child does it belong to? Also, general iteration is the way to go now. So just do:
For i,v in trinks do
ipairs can still be used, only if you want to stop at a nil value for some reason.
I changed the for loop to be For i,v in trinks do,
and also the print. Instead of 1.5, it prints “Golden Ring nil”
That is correct apart from the value of the ring itself, which doesn’t get picked up evidently
Its rather confusing because Worth is present inside of the object, so i don’t know what to do further.
Can you view the folder from the Explorer in the server mode and see if it does actually exist?
If it does, make sure there are no trailing whitespaces in the end,
If it does not, make sure the Archivable property is set to true for your Worth value.
Edit: Also, I think you meant to be referencing v.Worth.Value, not v.Value, assuming v are the Tools.
hey! sorry, but i forgot to reply earlier. after some tweaks i managed to get it working by using the idea given by Clinomanix. sorry if i wasted your time replying here, but i appreciate it reagrdless.