What is the issue?
My issue is that when I click the equip button, it sets the wrong value for what sword should be equipped.
What solutions have you tried so far?
I know the issue but I’m not sure what I need to do to fix it.
I have a table that gets a folder in ServerStorage and inserts all the items inside the folder into the table, as well as a value inside the item. I use getTools[elementIndex][1] on the local script to reference the sword’s name, and getTools[elementIndex][2] to reference the sword’s cost. The problem is, the elementIndex is not the same as what index I need for the specific sword they’re buying.
--create the table of items
getTools.OnServerInvoke = function(player)
local swords = {}
for _, sword in ipairs(serverStorage:WaitForChild("Swords"):GetChildren()) do
table.insert(swords, {sword.Name, sword:FindFirstChild("Cost").Value})
end
return swords
end
--reference the sword's name to change the gui's text accordingly
for elementIndex, element in ipairs(itemFrameChildren) do
if not element:IsA("ImageButton") then
table.remove(itemFrameChildren, elementIndex)
else
element.MouseButton1Click:Connect(function()
local swordName = getTools[elementIndex][1]
--portion im having an issue with
--result is in the localscript, and it is passing the wrong name through to the server
local result = purchaseItem:InvokeServer(selectedItem.Value)
--server is changing the value to the wrong thing
purchaseItem.OnServerInvoke = function(player, swordName)
local item = serverStorage.Swords[swordName]
local inventory = serverStorage.PlayerData[player.Name].Inventory
if inventory:FindFirstChild(swordName) then
local equippedSword = serverStorage.PlayerData[player.Name].EquippedSword
if equippedSword.Value ~= swordName then
equippedSword.Value = swordName
return "Equipped"
else
equippedSword.Value = "Default"
return "Unequipped"
end
else
local kills = player.leaderstats.Kills
if kills.Value >= item.Cost.Value then
kills.Value -= item.Cost.Value
local swordValue = Instance.new("ObjectValue")
swordValue.Name = swordName
swordValue.Parent = inventory
return true
else
return "PurchaseFailed"
end
end
end
If anyone could help I would be very appreciative and if you need extra explaining I can try my best.
