Hello Fellow Programmers!
So, First, All the events and Items are kept in ReplicatedStorage where they both can be seen by the server and the Client.
So, I decided to make a GUI Shop Button where a person selects an Item and Gets the following Details
I made a Module script for the buttons so that I don't use the same functions over and over again
And then I made a Server script called ItemTransaction where the Process takes place
But whenever I buy a second item, the first item always duplicates.
So here is the Code
MODULE SCRIPT
local replicatedStorage = game:GetService("ReplicatedStorage")
local PurchasingEvent = replicatedStorage.Events.PurchasingEvent
local player = game.Players.LocalPlayer
local module = {}
module.DisplayFunc = function(ItemName,Description,Price)
local DisplayFrame = game.Players.LocalPlayer.PlayerGui.GameShopGui.DisplayFrame
DisplayFrame.DisplayText.Text = Description
DisplayFrame.Price.Text = Price
DisplayFrame.BuyButton.MouseButton1Click:Connect(function()
PurchasingEvent:FireServer(ItemName,Price)
end)
end
return module
GUI BUTTON CODE
DisplayModule = require(game.ReplicatedStorage.Module.ModuleScript)
local ItemName = "Grenade"
local Button = script.Parent
local Price = 50
local Description = "KABOOOOOM!!"
Button.MouseButton1Click:Connect(function()
DisplayModule.DisplayFunc(ItemName,Description,Price)
end)
MAIN SERVER SCRIPT
local replicatedStorage = game:GetService("ReplicatedStorage")
local PurchasingEvent = replicatedStorage.Events.PurchasingEvent
local InsufficientMoneyEvent = replicatedStorage.Events.InsufficientMoneyEvent
local OwnedEvent = replicatedStorage.Events.OwnedEvent
PurchasingEvent.OnServerEvent:Connect(function(player,ItemName,Price)
local tool = replicatedStorage.Items:FindFirstChild(ItemName)
if tool then
if player.leaderstats.Gold.Value >= Price then
print(ItemName)
local Item = tool:Clone()
Item.Parent = player.Backpack
player.leaderstats.Gold.Value -= Price
Item = nil
else
InsufficientMoneyEvent:FireClient(player)
end
else
print("Error")
end
end)
If you know where is the error, please tell me.
Thank you very much for listening.
