When I buy something, a buy sound should play, and when I try to buy something without having the necessary money, an error sound should play and it works but for some reason, the error sound plays even when i buy something with enough cash.
The Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("BuyTool")
local BuySound = ReplicatedStorage:WaitForChild("PlayBuySound")
local NotEnoughSound = ReplicatedStorage:WaitForChild("PlayNotEnoughSound")
local function buyTool(player, tool)
if (player.Backpack:FindFirstChild(tool.Name)) then return end
if player.leaderstats["????"].Value >= tool.Price.Value then
player.leaderstats["????"].Value = player.leaderstats["????"].Value - tool.Price.Value
local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()
giveTool.Parent = player.Backpack
local giveTool = ReplicatedStorage.ShopItems[tool.Name]:Clone()
giveTool.Parent = player.StarterGear
BuySound:FireClient(player)
end
if player.leaderstats["????"].Value <= tool.Price.Value then
NotEnoughSound:FireClient(player)
end
end
remoteEvent.OnServerEvent:Connect(buyTool)

2 comments
im pretty sure you can delete the end on line 21, and edit line 22 so it's "elseif player.leaderstats["????"].Value <= tool.Price.Value". basically what you're doing is checking if the player has enough money, and then checking again if they don't have enough money (even if they already have the money). im not the best explainer but what i said should work
It Works!!! Thanks!!