MouseButton1Click not working with TextButton?

Hey everyone! So at the moment I was practicing Tweening GUI’s. I wanted to make something simple, so I made a play button with a main menu. when you click the button, it goes off to the left, and you spawn. For some odd reason, every time I tween a GUI, they never work. I’ve tried multiple things. I don’t think that it is the tween that is causing the issue, because I don’t get any errors. It might be the mouse click event. Here is my script…

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
character:WaitForChild("HumanoidRootPart").Anchored = true


local TweenService = game:GetService("TweenService")

repeat wait()
	   Camera.CameraType = Enum.CameraType.Scriptable
	until Camera.CameraType == Enum.CameraType.Scriptable 
Camera.CFrame = workspace.Camerapart.CFrame

local info = TweenInfo.new(20,Enum.EasingStyle.Sine,Enum.EasingDirection.Out)
local rotating = true

local MainMenu = game.StarterGui.MainMenu

local PlayButton = game.StarterGui.MainMenu.TextButton

local newinfo = TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out,0,false,0)

PlayButton.MouseButton1Click:Connect(function()
	print("PlayButton Clicked! Now the Tween will play!")
	local goal = {};
	goal.Position = UDim2.new(-0.2, 0, 0.71, 0)
	TweenService:Create(PlayButton,newinfo,goal):Play()
	
	wait(3)
	print("Player Spawned!")
	character.HumanoidRootPart.Anchored = false
	character.HumanoidRootPart.CFrame = workspace.SpawnPart.CFrame

	Camera.CameraType = Enum.CameraType.Custom

	MainMenu:Destroy()
end)

while rotating do
	local cameraTween = TweenService:Create(Camera,info, {CFrame = Camera.CFrame * CFrame.fromEulerAnglesXYZ(0, 360, 0);})
	cameraTween:Play()
	local blur = Instance.new("BlurEffect")
	blur.Parent = workspace.CurrentCamera
	blur.Enabled = true
	blur.Size = 10
	wait(0.02)
end

If anyone knows how to fix this, please let me know.

4 Likes

every time I tween a GUI, they never work

the tweening doesn’t work or the changing camera doesn’t work?

1 Like

I don’t know if it’s just me but I don’t see any MouseButton events with the TextButton in this script, if you could please provide that area.

1 Like

on the 10th line right below all of the variables

Ah, didn’t see the scroll bar lol. @NotMookit Are there any particular prints that don’t run?

1 Like

If it’s still available there is a plugin that allows you to tween anything with ease and it writes the code for you, after that all you need to do is play the tween when needed.

You are Tweening the GUI Right , Why are using Tween Service for it when roblox made an In-Built function to Tween Position and Size of GUIs.

Also does it Print the stuffs?

No, it didn’t print the stuff. I also use TweenService because it gives you more options than TweenPosition. TweenService is a more efficient way than TweenPosition.

Its a local script right? I have a feeling whether its because of the while loop , but usually events get fired even if there is a while loop.

Yeah, all of them didn’t run. So that is why I said MouseButton1Click might be the problem.

Not entirely sure, however this may be because the button goes into the PlayerGui instead of the StarterGui, and you’re trying to search for it in the StarterGui. (I’m not really experienced with this, so I may be completely wrong!)

I found out why , You are indexing StarterGui In a local Script. Thats the reason.

Is there anything covering the button or preventing you from pressing it? Such as some invisible frame or textlabel.

Nope, the text button shows when I click it, because roblox made it like that.

So PlayerGUi is what I should use? Not really sure how to use PlayerGUI.

Is this script inside of the GUI or outside of it?

Can I see the hierarchy of your StarterGui?

You can get the PlayerGui from the Player

local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local Frame = playerGui.Frame
1 Like

The local script is inside of the ScreenGUI and outside of the textbutton.

Picture code

I see, you refer to the GUi from the “game” I’d recommend grabbing it from the localscript using parent and variables.

1 Like