Button won't press for no reason?

The gui button labelled “yes” won’t let anything happen when I click it (a.k.a. Print(“Ok”) Wont work.

local player = game.Players.LocalPlayer

local character = player.Character:WaitForChild("Humanoid")

local leaderstats1 = player:FindFirstChild("leaderstats"):WaitForChild("EggCoins")

local leaderstats2 = game.ReplicatedStorage.w1

local button2 = script.Parent.Parent.Parent.Three.TextLabel

local three = script.Parent.Parent

local four = script.Parent.Parent.Parent.Three.TextLabel

local originalposition = script.Parent.Parent.Position

local MaxEggdog = 1

local trigger = game.ReplicatedStorage:WaitForChild("TropicalEggdog")



if MaxEggdog > 1 then
	four.Text = "You can't buy more than one skin!"
	--copy tween service here
end

local db = false

script.Parent.MouseButton1Click:Connect(function()
	print("Ok")
	if leaderstats1.Value >= 150 then
		print("2")
		--[[leaderstats2.Value = true
		button.Sound:Play()
		leaderstats.Value -= 150
	    trigger:FireServer()
	    MaxEggdog += 1
		script.Parent.Parent.Parent.Enabled = false ]]
		script.Parent.Sound:Play()
		print("3")
		local Info = TweenInfo.new(1.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out)
		local ts = game:GetService("TweenService")
		if not db then
			print("4")
			db = true
			three:TweenSizeAndPosition(
				UDim2.new(0.9, 0,0.9, 0), -- size
				UDim2.new(0.07, 0,-0.1, 0), -- pos
				Enum.EasingDirection.Out, --easing dir
				Enum.EasingStyle.Sine, --easing styl
				1.25,
				true

			)
			print("5")
			four:TweenPosition(
				UDim2.new(0.25, 0,0.85, 0),
				Enum.EasingDirection.Out,
				Enum.EasingStyle.Sine,
				1.25,
				true
			)
print("6")
			wait(3.5)
print("7")
			three:TweenSizeAndPosition(
				UDim2.new(1, 0,1, 0), -- size
				UDim2.new(0, 0,0, 0), -- pos
				Enum.EasingDirection.Out, --easing dir
				Enum.EasingStyle.Sine, --easing styl
				1.25,
				true
			)
print("8")
			four:TweenPosition(
				UDim2.new(0.25, 0,1.5, 0),
				Enum.EasingDirection.Out,
				Enum.EasingStyle.Sine,
				1.25,
				true
			)	
print("9")
			db = false
print("10")
		end
	end
end)

image

1 Like

is the print("Ok") statement inside the block being executed when you click the button?

Here’s some things you can do:

  • If you’re on mobile, .MouseButton1Click wont work, so perhaps you should use .Activated, that way, this will detect presses for both PC and mobile.

  • Set the Active property of the button to true, that way it allows to fire events such as button clicks and hover ons.

  • Check for the Zindex property, some GUI objects might be overlaying the button and you don’t even know it. It might cause some trouble.

  • I’m not sure where your script is located but make sure it’s located in somewhere like StarterGui (or in it’s descendants), ReplicatedFirst or StarterPlayerScripts.

He mentioned it isn’t at the beginning of the post’s description:

no

thiry charact thingy i guess

Oh yea I was confused, my bad! If it’s not working wouldn’t the issue be with the button and the script.

Edit: Connection between button and script

He could try changing it to

script.Parent.MouseButtonDown:Connect(function()
	print("Ok")
	-- rest of the code here
end)

There’s no such event, there are only three events in my knowledge, to detect GUI button clicks: .MouseButton1Click, .MouseButton2Click and .Activated.

Oh gotcha, then what you suggested here should work

1 Like

By the way, sorry if me correcting you irritates you lol, I just like to be a smart ahh

1 Like

Lmao no worries, how else would I learn?

1 Like

Doesn’t work

thiry charact thing

Where is your script located and what script is it? A local script or a server script? What device are you playing on?

PC,
image
(itemshop1)

Alright, I don’t know the solution to this then. I’ll let somebody else take over.

It does work on both platforms, so that can’t be the problem. Are you sure that part of the script is running? Maybe the execution got stuck at one of your :WaitForChild() at the beggining of the script, and it’s waiting for something that doesn’t exist.
Is there any infinite yield warning at console?

I could be wrong, but I would try deleting the button and completely remake the button. It could be from very annoying bug (I think it’s a bug) I’ve been encountering recently. The button won’t work, but after deleting it and recreating it, the new one works just fine.

I don’t know if this is your issue, but I would try it.

Doesn’t work

thiry charact thing

Would you mind sharing the place file? You do not have to, but it will make finding a solution much easier.