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

How do I make the Buy text box say "Not Enough" for when buying an Item?

Asked by
fr2013 88
6 years ago

This might be a dumb question but how can I say the text 'Not Enough' When the player doesn't have enough levels and not enough cash?

local price = script.Parent.Parent.Price
local level = script.Parent.Parent.Level
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = script.Parent.Parent.ItemName
local player = script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
    if player.Character:FindFirstChild(tool.Value) or player.Backpack:FindFirstChild(tool.value) then 
    script.Parent.Text = 'Bought'
    wait(1)
    script.Parent.Text = 'Buy'
    return end --Returns if player is holding (or have on the backpack) the tool name (tool.Value)
    if player.leaderstats:FindFirstChild("Level").Value >= level.Value then
        if player.leaderstats:FindFirstChild("Cash").Value >= price.Value then
            player.leaderstats:FindFirstChild("Cash").Value = player.leaderstats:FindFirstChild("Cash").Value - price.Value
            game.ReplicatedStorage.ShopBuy:FireServer(tool.Value)
        end
    end
end)
0
Try changing on line 13+14, .....("Level").Value >= .... Uhm, > is a symbol for below, but... below what? ( Below what level ) SwingingMelons -18 — 6y
0
Idk if I could put a else since it it has to be equal to or greater than the require level, because if it's below the required level, it need for it to say "Not Enough" and for the cash too. fr2013 88 — 6y
0
Is this a local script? Line 5 could be replaced to game.Players.LocalPlayer. Stay away from using so many parents. xPolarium 1388 — 6y
0
Yes it's a local script fr2013 88 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

****Make sure this is in a local script

And if it doesn't work let me know.

local price = script.Parent.Parent.Price
local level = script.Parent.Parent.Level
local tools = game.ReplicatedStorage:WaitForChild("Tools")
local tool = script.Parent.Parent.ItemName
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    if player.leaderstats:FindFirstChild("Level").Value >= level.Value then
        if player.leaderstats:FindFirstChild("Cash").Value >= price.Value then
            player.leaderstats:FindFirstChild("Cash").Value = player.leaderstats:FindFirstChild("Cash").Value - price.Value
            game.ReplicatedStorage.ShopBuy:FireServer(tool.Value)
            script.Parent.Text = "BOUGHT"
            script.Parent.Active = false
            script.Parent.AutoButtonColor = false
            script.Parent.Selectable = false
        end
    end
    if player.leaderstats:FindFirstChild("Level").Value <= level.Value then
        if player.leaderstats:FindFirstChild("Cash").Value <= price.Value then
            local OlText = ""..script.Parent.Text
            wait(.6)
            script.Parent.Text = "NOT ENOUGH CASH"
            wait(2)
            script.Parent.Text = OlText
        end
    end
end)
0
Thanks that actually worked fr2013 88 — 6y
0
you can use else :/ natonator63 29 — 6y
0
I know, it was a long script I gave up after 5 seconds trying to find the right line. namespace25 594 — 6y
0
Oof fr2013 88 — 6y
Ad

Answer this question