You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I want to make a game where you can sell items for robux. (like pls buy me, starving artists.)
- What is the issue? Include screenshots / videos if possible!
I get this error: Players.frostfairgr10.PlayerGui.InventoryGui.InventoryFrame.ItemsFrame.JohnDoeCard.LocalScript:5: attempt to index nil with ‘Activated’
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried to search on devfourm and found nothing, I’ve went in discord servers and nobody could help me.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
This is my main module:
local Main = {}
local MarketplaceService = game:GetService("MarketplaceService")
local HttpService = game:GetService("HttpService")
function Main.getCreatedGamepasses(player, assetId)
local userId = player.UserId
local gamepasses = {}
local GetGamesUrl1 = "https://games.RoProxy.com/v2/users/"
local GetGamesUrl2 = "/games?accessFilter=Public&sortOrder=Asc&limit=10"
local getGamesUrl = GetGamesUrl1..userId..GetGamesUrl2
local success,result = pcall(function()
return HttpService:GetAsync(getGamesUrl)
end)
if success then
pcall(function()
result = HttpService:JSONDecode(result)
for _,GameInfo in pairs(result["data"]) do
local gameId = GameInfo.id
local url = "https://games.RoProxy.com/v1/games/%s/game-passes?limit=100&sortOrder=Asc"
url = url:format(gameId)
local success2,result2 = pcall(function()
return HttpService:GetAsync(url)
end)
if success2 then
result2 = HttpService:JSONDecode(result2)
for _,GamepassDetail in pairs(result2["data"]) do
local gamepassId = GamepassDetail.id
table.insert(gamepasses,gamepassId)
end
end
end
end)
end
return gamepasses
end
function Main.LoadPricesFrame(plr, CreatedGamepasses)
local PlayerGui = plr:WaitForChild("PlayerGui")
local PricesFrame = PlayerGui:WaitForChild("MarketplaceGui"):WaitForChild("UploadFrame"):WaitForChild("SellingFrame"):WaitForChild("PricesFrame")
local PriceTemplate = PricesFrame:WaitForChild("PriceTemplate")
for i, v in CreatedGamepasses do
local Info = MarketplaceService:GetProductInfo(v, Enum.InfoType.GamePass)
local Price = Info.PriceInRobux
if Price ~= nil then
local NewPriceButton = PriceTemplate:Clone()
NewPriceButton.Text = "R$"..Price
NewPriceButton.Parent = PricesFrame
NewPriceButton.LayoutOrder = Price
NewPriceButton.Visible = true
NewPriceButton.Name = "PriceButton"
NewPriceButton:WaitForChild("Id").Value = v
i += 1
end
local Constraint = PricesFrame.UIGridLayout
PricesFrame.CanvasSize = UDim2.new(0, Constraint.AbsoluteContentSize.X, 0, Constraint.AbsoluteContentSize.Y)
end
end
function Main.ConvertToTable(string)
local Table = {}
for i in string:gmatch("%S+") do
table.insert(Table, i)
end
return Table
end
function Main.ConvertToString(table)
local result = ""
for _, value in ipairs(table) do
result = result .. tostring(value) .. " "
end
return result:sub(1, -2)
end
function Main.UpdateInventory(plr, Frame, InventoryTable)
local CardTemplates
if Frame.Parent.Name == "SellingFrame" then
CardTemplates = game.ServerStorage.UploadItemTemplates.Cards
else
CardTemplates = game.ServerStorage.InventoryItemTemplates.Cards
end
for i, v in Frame:GetChildren() do
if not v:IsA("UIGridLayout") and not v:IsA("UISizeConstraint") then
v:Destroy()
end
end
local Constraint = Frame.UIGridLayout
for i, v in InventoryTable do
local CardToCopy = CardTemplates:FindFirstChild(v)
if CardToCopy then
local Copy = CardToCopy:Clone()
Copy.Name = v
Copy.Parent = Frame
Copy.LocalScript.Enabled = true
end
end
Frame.CanvasSize = UDim2.new(0, Constraint.AbsoluteContentSize.X, 0, Constraint.AbsoluteContentSize.Y)
end
function Main.RemoveFromInventory(plr, ItemKey)
local Data = plr:WaitForChild("Data")
local InventoryString = Data:WaitForChild("Inventory")
local InventoryTable = Main.ConvertToTable(InventoryString.Value)
local ItemToRemove = table.find(InventoryTable, ItemKey)
table.remove(InventoryTable, ItemToRemove)
InventoryString.Value = Main.ConvertToString(InventoryTable)
end
function Main.AddToInventory(plr, ItemKey)
local Data = plr:WaitForChild("Data")
local InventoryString = Data:WaitForChild("Inventory")
InventoryString.Value = InventoryString.Value.." "..ItemKey
end
return Main
This is my Script for the Inventory:
local Main = require(script.Parent)
game.Players.PlayerAdded:Connect(function(plr)
local PlayerGui = plr:WaitForChild("PlayerGui")
local InventoryButton = PlayerGui:WaitForChild("MenuGui"):WaitForChild("MenuFrame"):WaitForChild("InventoryButton")
local ItemsFrame = PlayerGui:WaitForChild("InventoryGui"):WaitForChild("InventoryFrame"):WaitForChild("ItemsFrame")
local PlayerData = plr:WaitForChild("Data")
local InventoryString = PlayerData:WaitForChild("Inventory")
local InventoryTable = Main.ConvertToTable(InventoryString.Value)
Main.UpdateInventory(plr, plr.PlayerGui.InventoryGui.InventoryFrame.ItemsFrame, InventoryTable)
plr:WaitForChild("Data"):WaitForChild("Inventory").Changed:Connect(function()
local InventoryTable = Main.ConvertToTable(InventoryString.Value)
Main.UpdateInventory(plr, plr.PlayerGui.InventoryGui.InventoryFrame.ItemsFrame, InventoryTable)
end)
end)
And this is my script for the “Robux Marketplace”
local Main = require(script.Parent)
local UploadedItem = game.ReplicatedStorage.Events.UploadedItem
local PromptPlayerItem = game.ReplicatedStorage.Events.PromptPlayerItem
local PlayerBoughtItem = game.ReplicatedStorage.Events.PlayerBoughtItem
local MarketplaceService = game:GetService("MarketplaceService")
local ServerStorage = game:GetService("ServerStorage")
local UploadItemTemplates = ServerStorage.UploadItemTemplates.Cards
game.Players.PlayerAdded:Connect(function(plr)
local UploadFrame = plr:WaitForChild("PlayerGui"):WaitForChild("MarketplaceGui"):WaitForChild("UploadFrame")
local MarketplaceFrame = plr:WaitForChild("PlayerGui"):WaitForChild("MarketplaceGui"):WaitForChild("MarketplaceFrame")
local SellingFrame = UploadFrame:WaitForChild("SellingFrame")
local RefreshButton = SellingFrame:WaitForChild("RefreshButton")
local UploadButton = MarketplaceFrame:WaitForChild("UploadButton")
local CreatedGamepasses = Main.getCreatedGamepasses(plr)
Main.LoadPricesFrame(plr, CreatedGamepasses)
local InventoryTable = Main.ConvertToTable(plr:WaitForChild("Data"):WaitForChild("Inventory").Value)
Main.UpdateInventory(plr, plr.PlayerGui.MarketplaceGui.UploadFrame.SellingFrame.ItemsFrame, InventoryTable)
RefreshButton.MouseButton1Click:Connect(function() --Refresh Button Script
local PlayerGui = plr:WaitForChild("PlayerGui")
local PricesFrame = PlayerGui:WaitForChild("MarketplaceGui"):WaitForChild("UploadFrame"):WaitForChild("SellingFrame"):WaitForChild("PricesFrame")
local PriceTemplate = PricesFrame:WaitForChild("PriceTemplate")
local NumberOfFrames = PricesFrame:GetChildren()
for i, v in NumberOfFrames do
if v.Name == "PriceButton" then
v:Destroy()
end
i += 1
end
local CreatedGamepasses = Main.getCreatedGamepasses(plr)
Main.LoadPricesFrame(plr, CreatedGamepasses)
end)
plr:WaitForChild("Data"):WaitForChild("Inventory").Changed:Connect(function()
local InventoryTable = Main.ConvertToTable(plr:WaitForChild("Data"):WaitForChild("Inventory").Value)
Main.UpdateInventory(plr, plr.PlayerGui.MarketplaceGui.UploadFrame.SellingFrame.ItemsFrame, InventoryTable)
end)
-- Upload items to the marketplace script
UploadedItem.OnServerEvent:Connect(function(plr, GamepassId, Card)
local PlayerName = plr.Name
local Info = MarketplaceService:GetProductInfo(GamepassId.Value, Enum.InfoType.GamePass)
local Price = Info.PriceInRobux
local CardURL = UploadItemTemplates[Card].Image
local CardBackgroundColour3 = UploadItemTemplates[Card].BackgroundColor3
UploadedItem:FireAllClients(PlayerName, Price, GamepassId.Value, CardURL, CardBackgroundColour3, Card)
end)
end)
PromptPlayerItem.OnServerEvent:Connect(function(plr, GamepassId, Seller, ItemKey)
local Data = plr:WaitForChild("Data")
local CurrentItemSelected = Data:WaitForChild("CurrentItemSelected")
local CurrentItemSelectedOwner = Data:WaitForChild("CurrentItemSelectedOwner")
CurrentItemSelected.Value = ItemKey
CurrentItemSelectedOwner.Value = Seller
MarketplaceService:PromptGamePassPurchase(plr, GamepassId)
end)
PlayerBoughtItem.OnServerEvent:Connect(function(plr, ItemOwner, ItemSelected)
Main.RemoveFromInventory(game.Players[ItemOwner], ItemSelected)
Main.AddToInventory(plr, ItemSelected)
end)
And this is the script I get the error from:
local Button = script.Parent
local UploadedItem = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("UploadedItem")
local plr = game:GetService("Players").LocalPlayer
wait(1)
Button.Activated:Connect(function()
local ItemsFrame = script.Parent.Parent
local CurrentSelected = ItemsFrame:FindFirstChild("Selected")
if CurrentSelected then
CurrentSelected.Name = CurrentSelected.Config.ItemKey.Value
end
Button.Name = "Selected"
local PriceSelected = ItemsFrame.Parent.PricesFrame:FindFirstChild("Selected")
if PriceSelected then
UploadedItem:FireServer(PriceSelected.Id, Button.Config.ItemKey.Value)
end
end)
Sorry if my code is unoptimised, I am relatively new to scripting.
Keep in mind that a lot of this script could have nothing to do with the error.
The Error: Players.frostfairgr10.PlayerGui.InventoryGui.InventoryFrame.ItemsFrame.JohnDoeCard.LocalScript:5: attempt to index nil with ‘Activated’