My Textbutton is not working

Hello, I was working on my game and I decided to start creating the “Play” button for my game. What I wanted to achieve was that the player’s camera moved from one block to another and meanwhile the Play button, the other menu buttons and the game title became invisible, and that worked perfectly but now when I press the “Play” button nothing happens anymore. I have reviewed all my code and I don’t understand why it doesn’t work anymore. I also realized that from line 53 onwards the script no longer works (that’s where the “Play” button part is). There is no error in the Output.

I have used a LocalScript which is located in ‘StarterGui’ and a ModuleScript which is also located in ‘StarterGui’, it’s my first time using a ModuleScript, I think that’s why it doesn’t work.

image

Module Script:

local StarterGui = game:GetService("StarterGui")
local TweenService = game:GetService("TweenService")
local Player = game:GetService("Players")

local LobbyScreenUI = StarterGui.LobbyScreenUI

-- Buttons
local PlayButton = LobbyScreenUI.PlayButton
local SettingsButton = LobbyScreenUI.SettingsButton
local CreditsButton = LobbyScreenUI.CreditsButton

-- Player Cam
local camera = workspace.CurrentCamera


Connection = camera:GetPropertyChangedSignal("CameraType"):Connect(function()
	if camera.CameraType ~= Enum.CameraType.Scriptable then
		camera.CameraType = Enum.CameraType.Scriptable
	end
end)

camera.CameraType = Enum.CameraType.Scriptable
 --// camera.CFrame = CameraStart.CFrame


local UImodule = {}


function UImodule:Clicked()
	print("Play Button Clicked!")
	
	local Tween = TweenService:Create(camera, TweenInfo.new(2.5), {["CFrame"] = workspace.StartingGameCam.CFrame})

	Tween:Play()
end

function UImodule:DisableCoreGuiType()
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
end

function UImodule:EnableCoreGuiType()
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
end

return UImodule

Local Script:

-- Services
local Player = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local StarterGui = game:GetService("StarterGui")

local CameraStart = workspace:WaitForChild("LobbyPlrCam")
local camera = workspace.CurrentCamera


-- Needed Modules
local UI_Module = require(StarterGui.UI_Scripts:WaitForChild("UI_Module"))

-- Change player camera to Scriptable
Connection = camera:GetPropertyChangedSignal("CameraType"):Connect(function()
	if camera.CameraType ~= Enum.CameraType.Scriptable then
		camera.CameraType = Enum.CameraType.Scriptable
	end
end)

-- Change player camera CFrame to CameraStart in workspace
print("Player Camera is now Scriptable")
UI_Module:DisableCoreGuiType()
	
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CameraStart.CFrame

-- Remove Connection When Done -> 'Connection:Disconnect'

-- LobbyUI objects
local LobbyUI = StarterGui.LobbyScreenUI
local PlayButton = LobbyUI.PlayButton
local SettingsButton = LobbyUI.SettingsButton
local CreditsButton = LobbyUI.CreditsButton
local GameTitle = LobbyUI.GameTitle

local PlayButton_UIStroke = PlayButton.UIStroke
local CreditsButton_UIStroke = CreditsButton.UIStroke
local SettingsButton_UIStroke = SettingsButton.UIStroke
local SettingsImageLabel = SettingsButton.ImageLabel

-- IntermissionUI objects
local IntermissionUI = StarterGui.IntermisionUI
local IntermissionFrame = IntermissionUI.IntermissionFrame
local IntermissionText = IntermissionFrame.IntermissionText
local Intermission_UIstroke = IntermissionFrame.UIStroke

-- MapSelectionUI objects
local MapSelectionBackgroundFrame = IntermissionUI.MapSelectionBackgroundFrame
local MapSelectionBackground_UIstroke = MapSelectionBackgroundFrame.UIStroke
local ChaptersFolder = MapSelectionBackgroundFrame.MapSelectionBoxFrame:WaitForChild("Chapters")

-- Function when player clicks "Play" button
PlayButton.MouseButton1Click:Connect(function()
	UI_Module:Clicked() -- UImodule script
	
	print("Button Clicked (Local Script)")

	for _, UI in pairs({PlayButton, SettingsButton, CreditsButton, PlayButton_UIStroke, CreditsButton_UIStroke, SettingsButton_UIStroke}) do
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
		local tween = TweenService:Create(UI, tweenInfo, {Transparency = 1})
		
		local GameNameUITween = TweenService:Create(GameTitle, tweenInfo, {TextTransparency = 1})
		local SettingsImageTween = TweenService:Create(SettingsImageLabel, tweenInfo, {ImageTransparency = 1})
		
		tween:Play()
		GameNameUITween:Play()
		SettingsImageTween:Play()
	end
	
	task.wait(2.5)
	
	script.Parent.IntermisionUI.Enabled = true
end)

Help highly appreciated! :grinning:

Have you tried seeing if the event would run in a different local script?

It only runs in this Local Script, before it worked perfectly but I don’t know what I did that stopped working.

The problem is most likely that the PlayButton isn’t created until after the localscript has already tried to find it. Try

local PlayButton = LobbyScreenUI:WaitForChild('PlayButton')

I used “WaitForChild(‘PlayButton’)” as you told me but it still doesn’t work, and the Play Button was already created.

image

Does this still run?

print("Button Clicked (Local Script)")

No, everything from this part of the script no longer works:

-- Function when player clicks "Play" button
PlayButton.MouseButton1Click:Connect(function()
	UI_Module:Clicked() -- UImodule script

	print("Button Clicked (Local Script)")

	for _, UI in pairs({PlayButton, SettingsButton, CreditsButton, PlayButton_UIStroke, CreditsButton_UIStroke, SettingsButton_UIStroke}) do
		local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, false, 0)
		local tween = TweenService:Create(UI, tweenInfo, {Transparency = 1})

		local GameNameUITween = TweenService:Create(GameTitle, tweenInfo, {TextTransparency = 1})
		local SettingsImageTween = TweenService:Create(SettingsImageLabel, tweenInfo, {ImageTransparency = 1})

		tween:Play()
		GameNameUITween:Play()
		SettingsImageTween:Play()
	end

	task.wait(2.5)

	script.Parent.IntermisionUI.Enabled = true
end)

And button is active and still does not work.

Get rid of

UI_Module:Clicked() -- UImodule script

and see if that changes anything

I got rid of

UI_Module:Clicked() -- UImodule script

and it still doesn’t work, and I see no errors in the output.

1 Like

I think the problem is what I initially thought, which is that it’s creating the script before the UI. Try parenting the script to the screenUI that the button is in. Also, maybe to test just add a wait(1) at the start of the scirpt

If that doesn’t work just send me the rblx

nothing works

UntitledGame.rbxl (95.3 KB)

So here’s what fixed it: just put the local script inside LobbyScreenUI. Then set lobbyUI to be script.PArent.

1 Like