TextButton.MouseButton1Click event not working

  1. What do you want to achieve? Keep it simple and clear!

I made a gui and I want to connect a function to the MouseButton1Click event from a TextButton

  1. What is the issue? Include screenshots / videos if possible!

It simply don’t click! and it don’t connect… When I put the mouse above the button, it don’t turn lightish.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I think the button click it self for some reason so I made a check but it didn’t work so I removed it

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Player = game.Players.LocalPlayer
MenuGui = script.Parent

MenuGui.Button1.MouseButton1Click:Wait() --Waits Until click

script.Parent = Player.PlayerGui

function Loading()
	-- Loading Gui
	script.LoadingGui.Enabled = true
	Player.CharacterAdded:Wait()
	script.LoadingGui.Enabled = false
end

MenuGui:Destroy()

script.TeamSelectionGui.Enabled = true

script.TeamSelectionGui.Main.Police.MouseButton1Click:Connect(function()
	print("toucj")
	
	game.ReplicatedStorage:WaitForChild("MenuEvents").Play:FireServer("Police")
	script.TeamSelectionGui.Enabled = false
	Loading()
	
end)

script.TeamSelectionGui.Main.Prisoner.MouseButton1Click:Connect(function()
	print("touch")
	game.ReplicatedStorage:WaitForChild("MenuEvents").Play:FireServer("Prisoner")
	script.TeamSelectionGui.Enabled = false
	Loading()
end)

can you show the explorer of the gui? also does the output show anything?

1 Like

You should usually make functions a local function.

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

MenuGui.Button1.MouseButton1Click:Wait() --Waits Until click

local function Loading()
	-- Loading Gui
	script.LoadingGui.Enabled = true
	Player.CharacterAdded:Wait()
	script.LoadingGui.Enabled = false
end

MenuGui:Destroy()

script.TeamSelectionGui.Enabled = true

script.TeamSelectionGui.Main.Police.MouseButton1Click:Connect(function()
	print("toucj")
	
	game.ReplicatedStorage:WaitForChild("MenuEvents").Play:FireServer("Police")
	script.TeamSelectionGui.Enabled = false
	Loading()
	
end)

script.TeamSelectionGui.Main.Prisoner.MouseButton1Click:Connect(function()
	print("touch")
	game.ReplicatedStorage:WaitForChild("MenuEvents").Play:FireServer("Prisoner")
	script.TeamSelectionGui.Enabled = false
	Loading()
end)

Adding onto that, anything in StarterGui will transfer to the player’s PlayerGui, so no worries on that.

1 Like


Screenshot_7

You may want to also add 2 separate events for the team change, one for cops, the other for prisoners. This will make sure the player gets the exact team they need because passing a string through a remote event to change a team is not a good idea.

1 Like

MenuGui is the PlayerGui itself. I just noticed an issue on your code that you are trying to wait for a click on a button that is not displayed on the screen, since the button is parented on PlayerGui not a ScreenGui. Delete this line on your code:

MenuGui.Button1.MouseButton1Click:Wait() --Waits Until click
1 Like

oh, U right, let me see deez script

3 Likes

Yeah I changed the hierarchy and everything worked! Thanks

1 Like