Having Problems With Loops

I’m currently creating a project that is similar to the Pokemon games. Don’t worry nothing copyrighted. I’m having a bit of trouble making the name of a move appear correctly onto a move slot. What I need to happen is for a move to go onto a move slot for every single equipped move.

What’s wrong is that either the move gets on all of the move slots or it doesn’t appear at all.

Here is an example of what I’ve done:
(For this one all of the move slots become one move)

local function setMoveSlots(MoveSlots, playerMonster)
	for _, MoveSlot in ipairs(MoveSlots:GetChildren()) do
		for _, Move in pairs(MonstersModule.Monsters[playerMonster]["Moves"]) do
			if MoveSlot.Text ~= Move.Name or MoveSlot.Name == "MoveSlot" then
				print(MoveSlot.Text)
				MoveSlot.Text = Move.Name
			end	
		end
	end
end

What am I doing incorrectly?

Thank’s for reading! :grinning_face_with_smiling_eyes:

It is a little difficult to understand the use case without an idea of what your parameters are but if I’d guess, you might be missing a break or return.

Am I correct in saying that, only one ‘MoveSlot.Text’ should be set when this function calls?
If that is the case, just do a return to exit the function.

However, if you want to exit the current for loop, use break to allow the next ‘MoveSlot’ to be checked.

1 Like