Big Problem for Purchase Menu

  1. What do you want to achieve? Keep it simple and clear!

I am trying to create a unique system for shop where you can click proximity prompt object, for example… sword. Assuming you click the sword, it will activate Player’s Shop GUI with the price and title of that specific gear.

  1. What is the issue? Include screenshots / videos if possible!

I already created working system that will display correct gear name and price, but the problem is - how am I supposed to make purchase button working? It’s only ONE gui, I want to make a script that is capable of buying all gears, in one remote event. How can I transfer the price that was shown from proximity prompt to the gui’s purchase gui AND make it actually give gear?

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I thought of really goofy solution which is to just make list of separate scripts for each gear with purchases and stuff but it would be really horrible and just mess overall. Honestly, I ran out of ideas and doesn’t know what to do.

Here’s what my GUI hierachy looks like, incase if you want to know.
image

3 Likes

you should really show what you did for this “system”

if you want to send the item’s info through a remote event then you could just grab the item’s name from the gui you mentioned so you could check whether the player has enough money or not (could do this with a module script that has ‘item data’), and if the requested item is real

-- If player presses no then just close the gui

-- If the player presses yes then fire a remote called 'ShopEvent'
Confirmed.MouseButton1Click:Connect(function()
  ShopEvent:FireServer(Item.Name) -- Player wants to buy [Item.Name]
end)

Can you please send a video of the issue?

op is having trouble figuring out how to make the item’s purchasable
doesn’t really need a video

Oh … I didn’t know you could send information through remote events. How do you receive that information on the receiving side and respond to it though?

you could do this with a server script

-- Server script for a remote called 'ShopEvent'

local RS = game:GetService("ReplicatedStorage")
local ShopEvent = RS.ShopEvent

ShopEvent.OnServerEvent:Connect(function(Player, ItemName)
  -- Check if ItemName is a real item
  -- Then check if Player can afford the item
  -- A module script would help
end)

‘ShopEvent’ would be a RemoteEvent inside ReplicatedStorage

I am not sure if this would work, but this is section of proximity prompt script I wrote.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local itemTitle = "Special Sword"
local itemPrice = "$101"

local function deductMoney()
	local player = Players.LocalPlayer
	local leaderstats = player:WaitForChild("leaderstats")
	local cheez = leaderstats:WaitForChild("cheez")
	cheez.Value = cheez.Value - itemPrice
end


local proximityPrompt = script.Parent
proximityPrompt.Triggered:Connect(function(player)
	
	--// REFERENCES
	
	local testGui = player.PlayerGui.GearGUI
	local ShopEvent = game.ReplicatedStorage.ShopEvent
	
	local Confirmed = testGui.PurchaseMenu.YES
	local Denied = testGui.PurchaseMenu.NO
	local itemTitleLabel = testGui.PurchaseMenu.Item
	local itemPriceLabel = testGui.PurchaseMenu.Price
	
	--// SETUP (Change GUI's text and price)
	
	itemTitleLabel.Text = itemTitle
	itemPriceLabel.Text = itemPrice

	testGui.PurchaseMenu.Visible = true
	
	local ItemName = "Sword"
	
	Confirmed.MouseButton1Click:Connect(function()
		ShopEvent:FireServer(ItemName)
	end)
end)

Edit: How do I make the receiving side detect the information from remote event and subtract money from player’s stats if it works?

here’s how you could do it

-- LocalScript in StarterPlayerScripts

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer
local ShopEvent = RS.ShopEvent

local GearGui = LocalPlayer.PlayerGui:WaitForChild("GearGui")
local PurchaseMenu = GearGui:WaitForChild("PurchaseMenu")
local ItemPrompts = workspace:WaitForChild("ItemPrompts"):GetDescendants() -- Get all the prompts for each item

for _, Prompt in ItemPrompts do -- Loop through all of the prompts
	if not Prompt:IsA("ProximityPrompt") then continue end
	Prompt.Triggered:Connect(function(Player)
        -- Update the PurchaseMenu to match the triggered item prompt
		PurchaseMenu.Item.Text = Prompt.Item.Value
		PurchaseMenu.Price.Text = Prompt.Price.Value
		PurchaseMenu.Visible = true
	end)
end

local Confirmed, Denied = PurchaseMenu.Confirmed, PurchaseMenu.Denied

Denied.MouseButton1Click:Connect(function()
	PurchaseMenu.Visible = false
end)

Confirmed.MouseButton1Click:Connect(function()
	ShopEvent:FireServer(PurchaseMenu.Item.Text)
end)

ShopEvent.OnClientEvent:Connect(function(Purchased)
	if not Purchased then
		-- Either the item isn't real or player doesn't have enough
	else
		-- Update Gui to say 'Owned'
	end
end)
-- ServerScript in ServerScriptService

local RS = game:GetService("ReplicatedStorage")
local ShopEvent = RS.ShopEvent
local Items = require(--[[Module script]]) -- You could have the item's info in ModuleScript

local function DeductPlayerCheez(Player, Amount)
	Player.leaderstats.Cheez.Value -= Amount
end

ShopEvent.OnSeverEvent:Connect(function(Player, ItemName)
	local Leaderstats = Player:WaitForChild("leaderstats")
	local PlayerCheez = Leaderstats:WaitForChild("cheez")
	
	if not Items[ItemName] then return end -- Not a real item
	local item_price = Items[ItemName].price
	
	if PlayerCheez.Value < item_price then
		-- Tell the player that they do not have enough
		ShopEvent:FireClient(Player, false)
	else
		DeductPlayerCheez(Player, item_price)
		ShopEvent:FireClient(Player, true)
	end
	
	-- Save the player's data
end)

i’m not sure how you’re handling the ProximityPrompts but you shouldn’t have a script for each prompt
loop through a folder instead

1 Like

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