Invalid Argument #2 (String Expected, got nil)

This is all running in a Module script.

local Player                                    = game:GetService("Players").LocalPlayer
local TweenService                                = game:GetService("TweenService")
local GamePassService                            = game:GetService("GamePassService")
local MarketPlaceService                        = game:GetService("MarketplaceService")

local PlayerGui                                    = Player.PlayerGui
local StorePasses                                = PlayerGui.RespawnScripts.Store.Passes
local ClientHandler                             = PlayerGui.RespawnScripts.ClientHandler
local FeatureProducts                            = PlayerGui.RespawnScripts.Store.Featured

local Store                                     = {}

Store.GamePasses                                = {
    {"VIP",      767141329},
    {"Employee", 766502399}
}

Store.Products                                    = {
    {"Pin",      17002684973}
}

Store.Donations                                    = {    }

for i,v in pairs(Store.GamePasses) do
    StorePasses[v.Name].Purchase.MouseEnter:Connect(function(MouseEnter)
        ClientHandler.Hover:Play()
        local Info = TweenInfo.new(0.15, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0)
        TweenService:Create(StorePasses[v.Name].Purchase, Info, {BackgroundColor3 = Color3.fromRGB(147, 117, 87),}):Play() Info = nil
    end)
    StorePasses[v.Name].Purchase.MouseButton1Down:Connect(function(MouseButton)
        ClientHandler.Hover:Play() ClientHandler.ClickSound2:Play()
        MarketPlaceService:PromptGamePassPurchase(Player ,Store.GamePasses[v.Name])
    end)    
    StorePasses[v.Name].MouseLeave:Connect(function(MouseLeave)
        local Info = TweenInfo.new(0.15, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0)
        TweenService:Create(StorePasses[v.Name].Purchase, Info, {BackgroundColor3 = Color3.fromRGB(161, 128, 95),}):Play() Info = nil
    end)
end

for i, v in pairs(Store.Products) do
    FeatureProducts[v.Name].Purchase.MouseEnter:Connect(function(MouseEnter)
        ClientHandler.Hover:Play()
        local Info = TweenInfo.new(0.15, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0)
        TweenService:Create(FeatureProducts[v.Name].Purchase, Info, {BackgroundColor3 = Color3.fromRGB(147, 117, 87),}):Play() Info = nil
    end)
    FeatureProducts[v.Name].Purchase.MouseButton1Down:Connect(function(MouseButton)
        ClientHandler.Hover:Play() ClientHandler.ClickSound2:Play()
        MarketPlaceService:PromptProductPurchase(Player ,Store.Products[v.Name])
    end)
    FeatureProducts[v.Name].Purchase.MouseLeave:Connect(function(MouseLeave)
        local Info = TweenInfo.new(0.15, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out, 0, false, 0)
        TweenService:Create(FeatureProducts[v.Name].Purchase, Info, {BackgroundColor3 = Color3.fromRGB(161, 128, 95),}):Play() Info = nil
    end)    
end

return Store
1 Like

It appears to be breaking here

Why do you have so many spaces between variable names and their values? It makes the code a lot harder to read.

I think the issue is with your GamePasses and Products tables. You have arrays in arrays, but you never actually have a key called “Name” (which you are trying to reference), so it comes out as nil. You could try something like:

Store.GamePasses = {
    ["VIP"] = ID_HERE,
    ["Employee"] = ID_HERE
}

Okay so I attempted the suggestion of fixing the table to look like

It just created a new issue (attempt to index number with ‘Name’)
Also the reason for the spaces is it just makes the code easy to read on the Studio side

Store.GamePasses                                = {
	["VIP"]      			= 767141329,
	["Employee"] 			= 766502399
}

Store.Products                                  = {
	["Pin"]      			= 17002684973
}```

Try changing [v.Name] to [i].

Thank you very much for the help I appreciate it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.