Help with a for, in pairs loop

So im tryna make a skillbar system, i also have made a menu of sorts with keybinds, my issue is that whenever I try setting an attack to a specific key on my skillbar it sets the skill for all skill boxes. I’m trying to make it set to the specific number I choose rather then all of them

`local Players = game:GetService(“Players”).LocalPlayer

local PlayerGui = Players.PlayerGui
local rs = game:GetService(“ReplicatedStorage”)
local screengui = script.Parent.Parent.Parent
local keybindgui = screengui:WaitForChild(“Frame”).Keybindsgui

local k1 = keybindgui.Keybind1
local k2 = keybindgui.Keybind2

local attackevent = rs:WaitForChild(“Attackevent”)

local abilitiesfolder = Players.abilitiesfolder
local ShockWaveAttack = abilitiesfolder.ShockWaveAttack
local HotBarValue = abilitiesfolder.HotBarValue
local attackName = abilitiesfolder.attackName

local HotbarTable = {
PlayerGui.HotBarGui.HotbARframe.Ability1TextLabel,
PlayerGui.HotBarGui.HotbARframe.Ability2TextLabel,
PlayerGui.HotBarGui.HotbARframe.Ability3TextLabel,
PlayerGui.HotBarGui.HotbARframe.Ability4TextLabel,
PlayerGui.HotBarGui.HotbARframe.Ability5TextLabel,
PlayerGui.HotBarGui.HotbARframe.Ability6TextLabel,
PlayerGui.HotBarGui.HotbARframe.Ability7TextLabel,
}

HotBarValue.Changed:connect(function()
for i, v in pairs(HotbarTable) do
i = HotBarValue.Value
v.Text = attackName.Value
print(i)
end
end)

k1.MouseButton1Click:Connect(function()
local abilitiesfolder = Players.abilitiesfolder
local HotBarValue = abilitiesfolder.HotBarValue

HotBarValue.Value = 1

end)

k2.MouseButton1Click:Connect(function()
local abilitiesfolder = Players.abilitiesfolder
local HotBarValue = abilitiesfolder.HotBarValue

HotBarValue.Value = 2

end)

`

Try removing the pairs from the line for i, v in pairs(HotbarTable) do and it could work. This is because your table is an ipair, not a pair (you could also use ipairs instead of pairs, but I prefer not putting neither as Roblox automatically detects the type now :slight_smile:).

1 Like

This happens because you are looping through and setting each hotbar textlebel and value to the exact same thing (in this case HotBarValue.Value and attackName.Value).

It makes no difference. Ipairs and pairs will work the same on a table. A table is not defined by the type of iterator, it’s just a table. A dictionary however you need to use pairs. On tables you can use whatever iterator function you want.

2 Likes

Myself, I need hands-on to work with script problems. A simple copy-paste, so I can really look over the script. This is a picture, not a script. Please post scripts using the <> option.

I think i fixed it now (word minimum)

1 Like

i tried that and it still set all hotbar values to the same thing