Activated:Connect(function() error?

I am attempting to make a back and return button on ROBLOX with the Activated:Connect(function() event. For some reason, it won’t work in these two parts of code. I thought there was an issue with Activated, and I tried MouseButton1Click. It still didn’t work. Now, what makes it even weirder is that I have Activated in the same script, and it works for that event. Maybe I made a typo. Just thought I should have another pair of eyes check this.

BackButton.Activated:Connect(function()
    IGBackground.Visible = false
end)

ROBUXShopReturnButton.Activated:Connect(function()
    IGBackground.Visible = false
    Background.Visible = true
end)

I tried finding the buttons not using variables, and it still failed.

1 Like

To add, I checked the variables. All of them are good.

You forgot to include what the error is. Nothing looks wrong with this particular code by itself, which suggests that the problem is something else entirely.

The error is that it just won’t work. I tried making it only print something, guess what? Still didn’t work. Nothing was said in output.

If the code doesn’t run then the problem isn’t in the code that isn’t running. Where is the script located? Is it the right type? Is it disabled or in a certain place where scripts don’t run?

The script is located in StarterGui.

image

Full Script Code
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local amount_of_coins = player.money.Coins

local dominusempy = game.Lighting.DominusEmp

local IGBackground = script.Parent.IGBackground
local Background = script.Parent.Background
local BackButton = script.Parent.IGBackground.Back
local ParticleButton = IGBackground.Particle
local SmokeButton = IGBackground.Smoke
local SinisterBranchesButton = IGBackground.SinisterBranches
local DominusAstraButton = IGBackground.DominusAs
local PlayfulVampireButton = IGBackground.PlayfulVamp
local DominusEmpButton = IGBackground.DominusEmp
local DominusInferButton = IGBackground.DominusInfer
local ROBLOXFedoraButton = IGBackground.ROBLOXFedora
local ROBUXShopReturnButton = script.Parent.IGBackground.ROBUXShop
local TelamonHairButton = IGBackground.TelamonHair
local FireButton = IGBackground.Fire
local Title = IGBackground.Title
local Bottom = IGBackground.Bottom
local Coins = IGBackground.Coins
local NUMBER_OF_COINS = IGBackground.Number

DominusEmpButton.Activated:Connect(function()
	if amount_of_coins.Value >= 100 then
		amount_of_coins.Value = amount_of_coins.Value - 100
		
		local dominusempyreus = Instance.new("Accessory")
		dominusempyreus.Name = "Dominus_Empyreus"
 
		local handle = Instance.new("Part")
		handle.Name = "Handle"
		handle.Size = Vector3.new(2, 2, 2)
		handle.Parent = dominusempyreus
 
		local faceFrontAttachment = Instance.new("Attachment")
		faceFrontAttachment.Name = "HatAttachment"
		faceFrontAttachment.Position = Vector3.new(0, 0.5, -0)
		faceFrontAttachment.Parent = handle
 
		local mesh = Instance.new("SpecialMesh")
		mesh.Name = "Mesh"
		mesh.Scale = Vector3.new(1.05, 1.05, 1.05)
		mesh.MeshId = "rbxassetid://21057410"
		mesh.TextureId = "rbxassetid://21057378"
		mesh.Parent = handle

		humanoid:AddAccessory(dominusempyreus)
	else
		DominusEmpButton.TextLabel.Text = "Not enough cash."
	end
end)

while true do
	NUMBER_OF_COINS.Text = amount_of_coins.Value
	wait(2)
end

script.Parent.IGBackground.Back.Activated:Connect(function()
	script.Parent.IGBackground.Visible = false
end)

script.Parent.IGBackground.ROBUXShop.Activated:Connect(function()
	script.Parent.IGBackground.Visible = false
	script.Parent.Background.Visible = true
end)

You have an infinite loop before these two event connections. The reason the code does not run is because an infinite loop has to stop running first.

You put a while loop before connecting your events. Since it will never finish, the code below it won’t run. You should either position it to the bottom or run it inside spawn() (or don’t use it at all and use Changed event instead).

Ah thank you, although it now brings me to a new question. How do I make it so it doesn’t spawn the dominus halfway across the map?

DominusEmpButton.Activated:Connect(function()
	if amount_of_coins.Value >= 100 then
		amount_of_coins.Value = amount_of_coins.Value - 100
		
		local dominusempyreus = Instance.new("Accessory")
		dominusempyreus.Name = "Dominus_Empyreus"
 
		local handle = Instance.new("Part")
		handle.Name = "Handle"
		handle.Size = Vector3.new(2, 2, 2)
		handle.Parent = dominusempyreus
 
		local faceFrontAttachment = Instance.new("Attachment")
		faceFrontAttachment.Name = "HatAttachment"
		faceFrontAttachment.Position = Vector3.new(0, 0.5, -0)
		faceFrontAttachment.Parent = handle
 
		local mesh = Instance.new("SpecialMesh")
		mesh.Name = "Mesh"
		mesh.Scale = Vector3.new(1.05, 1.05, 1.05)
		mesh.MeshId = "rbxassetid://21057410"
		mesh.TextureId = "rbxassetid://21057378"
		mesh.Parent = handle

		humanoid:AddAccessory(dominusempyreus)
	else
		DominusEmpButton.TextLabel.Text = "Not enough cash."
	end
end)

AddAccessory doesn’t seem to work from the client. It creates the attachment but fails to create the weld. It shouldn’t be used from the client anyway, though.

This post was flagged by the community and is temporarily hidden.