ok so im making a “black market” system and I’m trying to make the item randomizer and somehow I am having problems that I can’t fix, any idea?
local stuff = script.Parent:WaitForChild("stuff"):GetChildren()
local folder = script.Parent:WaitForChild("Items")
for i, v in pairs(folder:GetChildren()) do
local random = math.random(1, #stuff)
v.Value = stuff[stuff[tostring(random)].Value]
print(stuff[stuff[tostring(random)].Value])
end
while wait(180) do
for i, v in pairs(folder:GetChildren()) do
local random = math.random(1, #stuff)
v.Value = stuff[stuff[tostring(random)].Value]
print(stuff[stuff[tostring(random)].Value])
end
end
local stuff = script.Parent:WaitForChild("stuff"):GetChildren()
local folder = script.Parent:WaitForChild("Items")
local function GetItem()
for _,v in pairs(folder:GetChildren()) do
local RandomItem = stuff[math.random(1, #stuff)]
v.Value = stuff[RandomItem]
print("Item Chosen: ", tostring(stuff[RandomItem]))
end
end
while task.wait(180) do
GetItem()
end
Looking back, stuff is not a Table, im pretty sure this only works on tables.
So maybe something like this:
local stuff = {
[1] = Item1;
[2] = Item2;
[3] = Item3;
}
local function GetItem()
for _,v in pairs(stuff) do
local RandomItem = stuff[math.random(1, #stuff)]
v.Value = stuff[RandomItem]
print("Item Chosen: ", tostring(stuff[RandomItem]))
end
end
another way is:
local Table_Stuff = {}
table.insert(stuff, Table_Stuff)
local function GetItem()
for _,v in pairs(Table_Stuff) do
local RandomItem = Table_Stuff[math.random(1, #Table_Stuff)]
v.Value = Table_Stuff[RandomItem]
print("Item Chosen: ", tostring(Table_Stuff[RandomItem]))
end
end
In your case, is v.Value expecting a string value or object value? This may be a case of mismatched values you’re trying to set here. Otherwise, try this:
local stuff = script.Parent:WaitForChild("stuff"):GetChildren()
local folder = script.Parent:WaitForChild("Items")
for i, v in pairs(folder:GetChildren()) do
local random = math.random(#stuff)
v.Value = stuff[random].Value
end
while wait(180) do
for i, v in pairs(folder:GetChildren()) do
local random = math.random(#stuff)
v.Value = stuff[random].Value
end
end