What do you want to achieve? My code to work? lmao
What is the issue? So basically, I have a shop GUI where you can buy weapons and stuff and the issue is that the buying prompt comes up for everything the player went through in the shop. Here’s what I mean: 2022-12-03 11-47-44
What solutions have you tried so far? I tried using a variable and change it to the item’s type and then checking it or whatever but that didn’t work.
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StoreItems = ReplicatedStorage:WaitForChild("Store Items")
local Stock = script.Parent.Parent:WaitForChild("Stock Frame").Stock
local Statistics = LocalPlayer.PlayerGui:WaitForChild("Store Gui").Contents["Main Frame"]["Item Statistics"]
--Buttons
local Weapons = script.Parent:WaitForChild("Weapons")
local Powerups = script.Parent:WaitForChild("Power-ups")
local Gamepasses = script.Parent:WaitForChild("Gamepasses")
local Exclusive = script.Parent:WaitForChild("Exclusive")
local ReceiptEvent = script.Parent:WaitForChild("ReceiptEvent")
local GiveToolEvent = script.Parent:WaitForChild("GiveToolEvent")
-- Here's the function where it all takes place in:
function OnClick(Folder)
Statistics.Visible = false
for _, element in pairs(Stock:GetChildren()) do
if not element:IsA("UIGridLayout") then
element:Destroy()
end
end
for _, instance in pairs(Folder:GetChildren()) do
local Clone = instance:Clone()
Clone.Parent = Stock
Clone.MouseButton1Click:Connect(function()
Statistics.Visible = true
local Attributes = Clone:GetAttributes()
Statistics.ItemName.Text = Clone.Name
for name, value in pairs(Attributes) do
if name == "Description" then
Statistics.Contents.Description.Text = "Description: "..value
elseif name == "Price" then
Statistics.Contents.Price.Text = "Price: "..value.."$"
elseif name == "Force" then
Statistics.Contents.Force.Text = "Force: "..value
end
end
Statistics.Contents["Buy Button"].MouseButton1Click:Connect(function()
local Type = Clone:GetAttribute("Type")
if Type == "Weapon" then
local Description = Clone:GetAttribute("Description")
local Price = Clone:GetAttribute("Price")
local Tool = Clone:GetAttribute("Tool")
GiveToolEvent:FireServer(Price, Tool)
elseif Type == "Power-up" then
elseif Type == "Gamepass" then
elseif Type == "Exclusive" then
local Description = Clone:GetAttribute("Description")
local Price = Clone:GetAttribute("Price")
local ModuleName = Clone:GetAttribute("ModuleName")
local ProductID = Clone:GetAttribute("ProductID")
ReceiptEvent:FireServer(ModuleName, ProductID)
end
end)
end)
end
end
--end of the function ofc
Weapons.MouseButton1Click:Connect(function()
OnClick(StoreItems:WaitForChild("Weapons"))
end)
Powerups.MouseButton1Click:Connect(function()
OnClick(StoreItems:WaitForChild("Power-Ups"))
end)
Gamepasses.MouseButton1Click:Connect(function()
OnClick(StoreItems:WaitForChild("Gamepasses"))
end)
Exclusive.MouseButton1Click:Connect(function()
OnClick(StoreItems:WaitForChild("Exclusive"))
end)
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StoreItems = ReplicatedStorage:WaitForChild("Store Items")
local Stock = script.Parent.Parent:WaitForChild("Stock Frame").Stock
local Statistics = LocalPlayer.PlayerGui:WaitForChild("Store Gui").Contents["Main Frame"]["Item Statistics"]
--Buttons
local Weapons = script.Parent:WaitForChild("Weapons")
local Powerups = script.Parent:WaitForChild("Power-ups")
local Gamepasses = script.Parent:WaitForChild("Gamepasses")
local Exclusive = script.Parent:WaitForChild("Exclusive")
local ReceiptEvent = script.Parent:WaitForChild("ReceiptEvent")
local GiveToolEvent = script.Parent:WaitForChild("GiveToolEvent")
local buyConnection
-- Here's the function where it all takes place in:
function OnClick(Folder)
Statistics.Visible = false
for _, element in pairs(Stock:GetChildren()) do
if not element:IsA("UIGridLayout") then
element:Destroy()
end
end
for _, instance in pairs(Folder:GetChildren()) do
local Clone = instance:Clone()
Clone.Parent = Stock
Clone.MouseButton1Click:Connect(function()
Statistics.Visible = true
local Attributes = Clone:GetAttributes()
Statistics.ItemName.Text = Clone.Name
for name, value in pairs(Attributes) do
if name == "Description" then
Statistics.Contents.Description.Text = "Description: "..value
elseif name == "Price" then
Statistics.Contents.Price.Text = "Price: "..value.."$"
elseif name == "Force" then
Statistics.Contents.Force.Text = "Force: "..value
end
end
if buyConnection then
buyConnection:Disconnect()
end
buyConnection = Statistics.Contents["Buy Button"].MouseButton1Click:Connect(function()
local Type = Clone:GetAttribute("Type")
if Type == "Weapon" then
local Description = Clone:GetAttribute("Description")
local Price = Clone:GetAttribute("Price")
local Tool = Clone:GetAttribute("Tool")
GiveToolEvent:FireServer(Price, Tool)
elseif Type == "Power-up" then
elseif Type == "Gamepass" then
elseif Type == "Exclusive" then
local Description = Clone:GetAttribute("Description")
local Price = Clone:GetAttribute("Price")
local ModuleName = Clone:GetAttribute("ModuleName")
local ProductID = Clone:GetAttribute("ProductID")
ReceiptEvent:FireServer(ModuleName, ProductID)
end
end)
end)
end
end
--end of the function ofc
Weapons.MouseButton1Click:Connect(function()
OnClick(StoreItems:WaitForChild("Weapons"))
end)
Powerups.MouseButton1Click:Connect(function()
OnClick(StoreItems:WaitForChild("Power-Ups"))
end)
Gamepasses.MouseButton1Click:Connect(function()
OnClick(StoreItems:WaitForChild("Gamepasses"))
end)
Exclusive.MouseButton1Click:Connect(function()
OnClick(StoreItems:WaitForChild("Exclusive"))
end)