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

this button, "on clicked" script is not functioning. elseif isn't working either?

Asked by 4 years ago

this script is a button to confirm a purchase.

however, when i run the code and try it out, it doesn't seem to work. (this is a localscript)

button = script.Parent
local Player = game.Players.LocalPlayer

local Tics = Player:WaitForChild("XPCASHFOLDER").Tics
local acquired = Player:WaitForChild("Brawlers").HitmanAcquired
local Title = script.Parent.Parent.Title

button.MouseButton1Click:Connect(function(clicked)
    if clicked and Tics.Value < 999 then
    Tics.Value = Tics.Value - 1000
    acquired.Value = true
    script.Parent.Parent.Visible = false
    elseif
        clicked and Tics.Value > 999 then
        Title.Text = "NOT ENOUGH"
        Title.TextColor = BrickColor.new("Bright red")
        wait(1)
        script.Parent.Parent.Visible = false
        Title.Text = "Are you sure you want to buy this?"
        Title.TextColor = BrickColor.new("Institutional white")
            return

    end
end)

1 answer

Log in to vote
1
Answered by
sleazel 1287 Moderation Voter
4 years ago

I do not recall MouseButton1Click event passing any arguments, nor I can find anything on API reference. I have always used this event without any anyway and it was working fine. It may be your issue. Try this instead:

button = script.Parent
local Player = game.Players.LocalPlayer

local Tics = Player:WaitForChild("XPCASHFOLDER").Tics
local acquired = Player:WaitForChild("Brawlers").HitmanAcquired
local Title = script.Parent.Parent.Title

button.MouseButton1Click:Connect(function()

    if Tics.Value < 999 then
        Tics.Value = Tics.Value - 1000
        acquired.Value = true
        script.Parent.Parent.Visible = false
    elseif Tics.Value > 999 then
        Title.Text = "NOT ENOUGH"
        Title.TextColor = BrickColor.new("Bright red")
        wait(1)
        script.Parent.Parent.Visible = false
        Title.Text = "Are you sure you want to buy this?"
        Title.TextColor = BrickColor.new("Institutional white")
        --return --you do not need that return statement
    end

end)

Have a nice scripting session.

Ad

Answer this question