Text Button not even executing its code

I want to make it so that when the Change Team button is clicked, the Frame to be tween sized to the size of 0.379, 0, 0.567, 0 but for some reason it doesn’t do that!

I went to multiple posts about people having trouble with their Text Buttons not working but it doesn’t help me because their situations are different while my Text Button doesn’t even execute the code it’s supposed to.

It’s a LocalScript inside the Change Team button.
image

This is my code below:

local Players = game:GetService("Players")
local GroupService = game:GetService("GroupService")
local GROUP_ID = 7913453

local allies = {}

local pages = GroupService:GetAlliesAsync(GROUP_ID)

while true do
	for _, group in pairs(pages:GetCurrentPage()) do
		table.insert(allies, group)
	end
	if pages.IsFinished then
		break
	end
	pages:AdvanceToNextPageAsync()
end

local function clearScrollingFrame()
	for _, v in pairs(script.Parent.Frame.ScrollingFrame:GetChildren()) do
		if v:IsA("Frame") and v.Name ~= "Template" then
			v:Destroy()
		end
	end
end

local cam = workspace.CurrentCamera

local function load()
	clearScrollingFrame()

	script.Parent.ChangeTeam.Visible = false

	if Players.LocalPlayer:IsInGroup(GROUP_ID) then
		local mainGroupClone = script.Parent.Frame.ScrollingFrame.Template:Clone()
		mainGroupClone.Name = "MainGroup"
		mainGroupClone.Visible = true
		mainGroupClone.ImageButton.Activated:Connect(function()
			script.Click:Play()
			cam.CameraType = Enum.CameraType.Custom
			for _, v in pairs(game.Lighting:GetChildren()) do
				if v:IsA("BlurEffect") then
					v:Destroy()
				end
			end
			game.ReplicatedStorage.Spawn:FireServer("Main")
			script.Parent.Frame:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.17, true)
			script.Parent.ChangeTeam.Visible = true
		end)
		mainGroupClone.Parent = script.Parent.Frame.ScrollingFrame

		for _, division in pairs(allies) do
			if Players.LocalPlayer:IsInGroup(division.Id) then
				local clone = script.Parent.Frame.ScrollingFrame.Template:Clone()
				clone.Name = division.Name
				clone.Visible = true
				clone.ImageButton.Image = division.EmblemUrl
				clone.TextLabel.Text = division.Name
				clone.ImageButton.Activated:Connect(function()
					script.Click:Play()
					for _, v in pairs(game.Lighting:GetChildren()) do
						if v:IsA("BlurEffect") then
							v:Destroy()
						end
					end
					if string.find(division.Name, "Coruscant Guard") then
						game.ReplicatedStorage.Spawn:FireServer("Coruscant Guard")
					elseif string.find(division.Name, "Red Guard") then
						game.ReplicatedStorage.Spawn:FireServer("Red Guard")
					end

					script.Parent.Frame:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.17, true)
					script.Parent.ChangeTeam.Visible = true
				end)
				clone.Parent = script.Parent.Frame.ScrollingFrame
			end
		end
	else
		local immigrantClone = script.Parent.Frame.ScrollingFrame.Template:Clone()
		immigrantClone.Name = "Immigrant"
		immigrantClone.TextLabel.Text = "Immigrant"
		immigrantClone.Visible = true
		immigrantClone.ImageButton.Image = "rbxassetid://14932361857"
		immigrantClone.ImageButton.Activated:Connect(function()
			script.Click:Play()
			for _, v in pairs(game.Lighting:GetChildren()) do
				if v:IsA("BlurEffect") then
					v:Destroy()
				end
			end
			game.ReplicatedStorage.Spawn:FireServer("Immigrant")

			script.Parent.Frame:TweenSize(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.17, true)
			script.Parent.ChangeTeam.Visible = false
		end)
		immigrantClone.Parent = script.Parent.Frame.ScrollingFrame
	end
end

script.Parent.Activated:Connect(function()
	print("button clicked") -- doesn't fire

	local blur = Instance.new("BlurEffect")
	blur.Size = 17
	blur.Name = "SpawnBlur"
	blur.Parent = game:GetService("Lighting")

	script.Parent.Frame.Size = UDim2.new(0, 0, 0, 0)
	script.Parent.Frame.Visible = true

	script.Parent.Frame:TweenSize(UDim2.new(0.379, 0, 0.567, 0), Enum.EasingDirection.In, Enum.EasingStyle.Elastic, 0.17, true)

	load()
end)

I need help ASAP!

1 Like

Try to use .MouseButton1Click instead, I believe that .activated is referencing another property.

2 Likes

Thank you so much! I was trying to figure this out for over 2 hours!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.