Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

?I'm having trouble with this loop assigning the value to the NumberValues

This code is supposed to go through every value in the table and assign it a random number from 0 to 50 (The minimum was set to 1 for testing reasons).

local function Init()
	local p = script.Parent:GetChildren()
	for i, v in ipairs(p) do
		if p[i].Name == "Part" then
			parts[i] = p[i]
			local value = Instance.new("NumberValue")
			value.Parent = p[i]
			value.Value = math.random(1, 50)
			value.Value = states[i]
			print(p[i].Name..i.." has the value of "..p[i].Value.Value)
		end
	end
end

However, the values are being instantiated, but are not being assigned with the random number. The output looks like this

Part1 has the value of 0
Part2 has the value of 0
Part3 has the value of 0
Part4 has the value of 0
Part5 has the value of 0
Part6 has the value of 0
Part7 has the value of 0
Part8 has the value of 0
Part9 has the value of 0
Part10 has the value of 0
Part11 has the value of 0
Part12 has the value of 0
Part13 has the value of 0
Part14 has the value of 0
Part15 has the value of 0
Part16 has the value of 0
Part17 has the value of 0
Part18 has the value of 0
Part19 has the value of 0
Part20 has the value of 0
Part21 has the value of 0
Part22 has the value of 0
Part23 has the value of 0
Part24 has the value of 0

It worked before, but I have no idea why it just broke today.

1 answer

✓ Accepted answer

states[i] is 0, or not a number.

Check on line 9. That was easy.

1 comment

0

Oops.

This discussion is preserved as it was. New answers, comments, and votes are closed.