Module script Repeating

So im trying to create an hotbar/inventory system, Essentially, the for i,v loop is looping through a skills folder to find a skill that matches the skill name. If it does, then it loops through the keybindframe, which is where the hotbar is, where the player can see the keybinds: here is what I’m talking about


The bottom bar is the keybind frame, the top portion is the inventory.
Whenever the inventory is active, the keybind frames appear. This is done to show the players where they can put the skills; however, while the inventory is disabled, the hotbar only shows what skills they have in their hotbar.
it loops through those 10 squares, and if it’s taken, it adds 1 to the taken amount.
The amount value is there to let the system know whether the player has any space on their hotbar. If all the values are taken, then the item is put into the inventory.
The looping through the backpack in my new script should ensure that if the player already has the skill, it doesn’t give it to them again.

Problem: Amt value is multiplying by 10 rather then increasing by 1 which is making it so that 10 frames are created instead of 1

Inventory system.rbxl (73.9 KB)

local rs = game:GetService("ReplicatedStorage")

local module = {}
local amt = 0
local debounce = false

module.skillgiver = function(player, SkillName)
	local OldAmount = amt
	local skillsFolder = rs:WaitForChild("SkillsFolder")
	for i,v in skillsFolder:GetChildren() do
		print('works')
		if v.Name ~= SkillName then return end
		if v.Name == SkillName then
			
			local SkillClone = v:Clone()
			SkillClone.Parent = player.Backpack
			for _, s in ipairs(player.PlayerGui.keybindFrame.Frame:GetChildren()) do
				if not s:IsA("TextLabel") or debounce then continue end
				debounce = true 

			    if not s.Taken.Value then
					local UiClone = rs.TextLabel:Clone()
					UiClone.Position = s.Position
				    UiClone.Parent = player.PlayerGui.HotbarFrame.Frame

					s.Taken.Value = true
					amt += 1
				elseif amt < 10 then 
					amt += 1
							
				else 
					local UiClone = rs.TextLabel:Clone()
				    UiClone.TextLabel.Visible = false
					UiClone.Parent = player.PlayerGui.Inventory.ScrollingFrame
				end

				print(OldAmount)
				debounce = false 
			end
		end
	end
end
	
return module
2 Likes

i could be wrong on this, but:

elseif amt < 10 then 
		amt += 1

is the problem, amt is also below 10, so that if statement will also run (unless the if statements stop running once the first one runs, not sure on that)

to verify my theory, try printing amt in both if statements

i put a print statment in the first if statment and htis is what happens
image
how do i make it stop once it generates a frame, i think thats the issue
the second print statment in the elseif section doesnt run but the third one runs
i think the issue is to do with the first if statement maybe?

edit: This issue is solved

necroposting!!!

what did you do? cause i lowkey have no idea