Why doesn't this image button activate my dialogue gui?

Why doesn’t my ImageButton play this script? No errors, so I have no clue what the problem could be.

game.StarterGui.Menu.ImageButton.MouseButton1Click:Connect(function()

	local TextLabel = script.Parent
	local Text

	local function SoundEffect()
		local Sound = Instance.new("Sound", workspace)
		Sound.Name = "TextSound"
		Sound.SoundId = "https://www.roblox.com/asset/?id=10362620616"
		Sound.PlaybackSpeed = 1
		Sound.Volume = 1
		Sound:Play()
		coroutine.resume(coroutine.create(function()
			wait(1)
			Sound:Destroy()
		end))
	end

	local function SetText(word)
		Text = word
		for i = 1, #Text do 
			TextLabel.Text = string.sub(Text, 1, i)
			SoundEffect()
			TextLabel.TextColor3 = Color3.fromRGB(255,255,255)
			wait(0.05)
		end
	end

	wait(3)
	SetText("Dialogue Test, Dialogue Test, Dialogue Test, Dialogue Test, ") 
	wait(3)
	SetText("Dialogue Test, Dialogue Test, Dialogue Test, Dialogue Test, ")
	wait(1)
	SetText("Dialogue Test, Dialogue Test, Dialogue Test, Dialogue Test, ")
	
end)

Dont use StarterGui to detect if button is pressed, as it wont work. Could you show where is this script in explorer ?

sure thing

image

Got it to work, but now I have another problem of only displaying the UI when the button has been pressed. I’ve tried turning Visible to false in studio and then enabling it in with the script. I’ve tried turning Enabled to false in studio and enabling it with scripts, but that didn’t work either. So I’m not sure how to do it

Here’s the layout just in case:
image
Expanded
image

TextButton’s Textcolor is not set to the Background Color?

are you referring to

TextLabel.TextColor3 = Color3.fromRGB(255,255,255)

Well, lets say you want to only dialogue frame make visible, when button is pressed, then it could look something like this

local button = --your path to that image button
button.MouseButton1Click:Connect(function()
    local dialogueFrame = script.Parent.Parent
    dialogueFrame.Visible = true
end)
1 Like

edited it to work for all the UI elements and that seemed to do it. Thanks as always!