I really can’t believe that the first person who came here couldn’t solve this problem… to begin with, this part is wrong:
game.ReplicatedStorage.ShopEvents.Purchase.OnServerEvent:Connect(function(player, itemcost)
print (itemcost)
if player.leaderstats.Coins.Value == itemcost then
player.leaderstats.Coins.Value -= itemcost
else
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = true
player.PlayerGui.GameInventory.DeleteOneMsg.Msg.Text = "You don't have enough coins."
--player.PlayerGui.GameInventory.Frame.Visible = true
wait(2)
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = false
end
change it to:
game.ReplicatedStorage.ShopEvents.Purchase.OnServerEvent:Connect(function(player, itemcost)
print (itemcost)
if player.leaderstats.Coins.Value >= itemcost then
player.leaderstats.Coins.Value -= itemcost
else
game.ReplicatedStorage.ShopEvents.Purchase:FireClient(player)
end
end)
and then in the local script put:
slot.ImageButton.MouseButton1Click:Connect(function(player)
-- Get the first child of the ViewportFrame.Model and set the itemName variable to its Name property
local itemModel = slot.ViewportFrame.Model:GetChildren()[1]
local itemName = itemModel.Name
local player = game.Players.LocalPlayer
print(player) -- This will print the value of player in the console
print(player.leaderstats)
-- Check if the slot has an item equipped
local shopitem = objDisplay:GetChildren()[1]
local itemcost = shopitem:FindFirstChild("Cost").Value
if equipped == true and itemcost > player.leaderstats:FindFirstChild("Coins").Value then
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = true
player.PlayerGui.GameInventory.DeleteOneMsg.Msg.Text = "You don't have enough coins."
--player.PlayerGui.GameInventory.Frame.Visible = true
wait(2)
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = false
else
if equipped == true and itemcost <= player.leaderstats:FindFirstChild("Coins").Value then
local event = game.ReplicatedStorage.InvEvents.PickUp
local purchaseitem = game.ReplicatedStorage.ShopEvents.Purchase
local item = itemName
local firstChild = itemModel
local itemdescription = firstChild:FindFirstChild("Desc").Value
event:FireServer(item, itemdescription)
purchaseitem:FireServer(itemcost)
purchaseitem.OnClientEvent:Connect(function()
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = true
player.PlayerGui.GameInventory.DeleteOneMsg.Msg.Text = "You don't have enough coins."
--player.PlayerGui.GameInventory.Frame.Visible = true
wait(2)
player.PlayerGui.GameInventory.DeleteOneMsg.Visible = false
end)
why change that way? Well, for the server to be more optimized, it is not recommended to change guis on the server side, also, if you change the value on the client side, the server will not detect it, therefore put in the current:
set it to appear instead of client say “server” at that time you can change the value on the server side.