.script is having a stroke

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

image

Might work:

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

issue still consists as stringvalue of “stuff[randomitem]” is considered nil

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

still returns nil

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
1 Like

Fixed my error, try again?

303030303030303030

actually, im connecting this to another script so I would have to slap the values into a group of values in order to make it work for another script

you worked it out, now i would have to mess around with the other script so it works lol thanks
image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.