Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"NotEnoughCash" Sound Plays Even when i Buy something with enough Cash?

Asked by 3 years ago

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)
0
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 meteorcrasher118 35 — 3y
0
It Works!!! Thanks!! benjinanas 50 — 3y

Answer this question