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

Weird error that should not be happening?

slots = script.Parent.Frame.Control:GetChildren()
--gui clickage--
for i,v in pairs(slots) do
	if tonumber(v.Name) then
		v.MouseButton1Click:connect(function()
			v.Visible = false
			local numClicked = v.Name
			print(numClicked)--prints one
			print(selected[1])--prints namey namey(expected to)
			print(selected[numClicked])--prints nil
end
end
end)

It's not really an error in the output, but it has been proven by prints that it should not print nil at all.

btw Selected is a table that has one thing in it, a string called namey namey.

So yes, I think this is quite the odd error, as ithas been printificaciously proven, that this should not print nil.

3 comments

0

could it be that you're trying to print the first index value of selected within the slots index? like selected is a different table but you're trying to tell it to print the first value of the selected table but you're saying that while in the slots table. does that make sense or am I just talking crazy? haha

0

Red line 7 local numClicked = v.Name

0

Did that answer the question?

1 answer

✓ Accepted answer

I found your problem.

slots = script.Parent.Frame.Control:GetChildren()
--gui clickage--
for i,v in pairs(slots) do
	if tonumber(v.Name) then
		v.MouseButton1Click:connect(function()
			v.Visible = false
			local numClicked = v.Name
			print(numClicked)--prints one
			print(selected[1])--prints namey namey(expected to)
			print(selected[tonumber(numClicked)]) -- You forgot to make it tonumber(v.Name) rather than the name itself because you were getting the index as a string value, and not a number.
		end
	end
end)

3 comments

0

You could just change numClicked to tonumber(v.Name) instead to save you the troubles.

0

OH, thank you. I only used tonumber because all of the gui's i needed have names that are numbers, the ones with non-number names didn't get to use that. I didn't think i had you use tonumber on numClicked, thank you!

0

No problem.

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