What i'm trying to do is edit a variable so when a child is added/removed it will connect a function..
wait(3) player = game.Players.LocalPlayer function Party() this = nil this = game.Lighting.Party:FindFirstChild(player.InParty.Value) end function update() Party() print(this) local Slots = script.Parent:GetChildren() local ok = this:GetChildren() wait(1) for i = 1, #Slots do for a = 1, #ok do if i == a then Slots[i].Text = ok[a].Name end end end end function deupdate() local retext = script.Parent:GetChildren() for i = 1, #retext do if retext[i]:IsA("TextLabel") then retext[i].Text = "" end end update() end update() Party() this.ChildAdded:connect(deupdate) this.ChildRemoved:connect(deupdate)
in function Party it's meant to update the variable "this" It only works with the original variable. Do I also need to update the connects at the bottom of the script?
Yes you also need to update the connects at the bottom. Also, you should declare the this variable beforehand.
wait(3) local player = game.Players.LocalPlayer local this local update local deupdate function Party() this = game.Lighting.Party:FindFirstChild(player.InParty.Value) this.ChildAdded:connect(deupdate) this.ChildRemoved:connect(deupdate) end function update() Party() print(this) local Slots = script.Parent:GetChildren() local ok = this:GetChildren() wait(1) for i = 1, #Slots do for a = 1, #ok do if i == a then Slots[i].Text = ok[a].Name end end end end function deupdate() local retext = script.Parent:GetChildren() for i = 1, #retext do if retext[i]:IsA("TextLabel") then retext[i].Text = "" end end update() end update() Party()