Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.