Help with connection

So I know a few things connection you can connect them to events like this:

Connection = script.Parent.ChildAdded:Connect(function()

and Disconnect them

:Disconnect()

but how would I hook a connection with this getchildren thing

				for i, v in ipairs(PlayerDragons.DragonLevels:GetChildren()) do
					v.Changed:Connect(function()
						print("Changed")
						if v.Value == 2 then
							RewardPlayer(player,InProgress.GetADragonToLevel2,true,true)
							QuestEvents.RemoveEvent:FireClient(player,"Level a Dragon up to level 2")
							InProgress.GetADragonToLevel2.Parent = CompletedQuests
							print(player.DisplayName.." has completed get a dragon to level 2 quest")
							Questing.Value = false
						end
					end)
				end
1 Like

Connections (RBXScriptConnections) are returned when you use the :Connect() function on an Event (RBXScriptSignal).

The :GetChildren() function does not return a connection, it returns an array/table. It looks like the only connection you’ve made to an event is:

v.Changed:Connect(function()

Now you just need to define a variable to it.

local con = v.Changed:Connect(function()
1 Like

Hey, can you help me with another connection issue I have?

So I am making a inventory and a ui to equip the dragon and it equips all the dragons that is in the inventory instead of the 1 dragon

here is the script

local Sample = script:WaitForChild("Sample")
local DragonList = script.Parent.Frame:WaitForChild("DragonScrollingFrame")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local DragonSlots = player:WaitForChild("DragonSlots")
local StatsFrame = script.Parent.Frame.StatsFrame.Dragon
local Events = game.ReplicatedStorage.RemoteEvents.Server.Dragon
local Dragons = game.ReplicatedStorage.Storage.Dragons
local DragonNames = player:WaitForChild("PlayerDragons"):WaitForChild("DragonNames")

local Slots = script.Parent.Slots
local CurrentlyEquipped = script.Parent.CurrentlyEquipped
local connections = {}
local EquipConnection = {}
local bv = false

function checkSlots()
	Slots.Value = 0

	for i, v in pairs(DragonSlots:GetChildren()) do
		Slots.Value += 1
	end
end

DragonSlots.Changed:Connect(function()
	checkSlots()
end)

CurrentlyEquipped.Changed:Connect(function()
	if Slots.Value >= 2 then
		if CurrentlyEquipped.Value > Slots.Value then
			CurrentlyEquipped.Value = Slots.Value
		end
	end
end)

function addtoFrame(Dragon,Slot,DragonName)
	checkSlots()

	local DragonTemplate = Sample:Clone()
	DragonTemplate.Name = Dragon.Name
	DragonTemplate.Parent = DragonList

	DragonTemplate:WaitForChild("DragonName").Text = DragonName.Value

	DragonName.Changed:Connect(function()
		DragonTemplate:WaitForChild("DragonName").Text = DragonName.Value
	end)

	local dragonClone = Dragon:Clone()
	dragonClone.Parent = DragonTemplate.ViewportFrame

	local db = false

	if db == true then return end 

	db = true
	
	EquipConnection[#EquipConnection + 1] = StatsFrame.Equip.MouseButton1Click:Connect(function()
		if bv == false then
			Events.Equip:FireServer(player,Dragons:FindFirstChild(DragonTemplate.Name),Slot)
			CurrentlyEquipped.Value += 1
		else
			Events.UnEquip:FireServer(character,Dragon,Slot)
			CurrentlyEquipped.Value -= 1
		end
	end)

	connections[#connections + 1] = DragonTemplate.MouseButton1Click:Connect(function()
		if StatsFrame.Visible ~= true then
			StatsFrame.Visible = true
		elseif StatsFrame.Visible == true then
			StatsFrame.Visible = false
		end
	end)

	StatsFrame:GetPropertyChangedSignal("Visible"):Connect(function()
		if StatsFrame.Visible == false then
			EquipConnection:Disconnect()
		end
	end)

	print("Addtoframe is done")
end

Events.AddToFrame.OnClientEvent:Connect(function(Dragon,Slot,DragonName)
	addtoFrame(Dragon,Slot,DragonName)
end)
1 Like