Why is .DescendantAdded not running?

  1. I’m trying to make a script that when an existing instance is parented to a folder, a function runs that sets up some variables and whatnot.
local function ButtonSet(Button)
	if Button then
		Button:SetAttribute("Debounce", false)
		
		Button.Touched:Connect(function(otherPart)

			if not Button:GetAttribute("Debounce") then
				Button:SetAttribute("Debounce", true)

				local Player = PlayerCheck(otherPart)
				
				if Player then
					OnPurchase(Player, Button)
				end

				task.wait(1)
				Button:SetAttribute("Debounce", false)		
			end
		end)	
	end
for i, Button in ipairs(Buttons:GetChildren()) do
	ButtonSet(Button)
end

Buttons.DescendantAdded:Connect(ButtonSet)

idk what going on with code block

  1. I’ve looked in documentation and the dev forum, found nothing.
1 Like

button is equal to the descendant added


-- services 
local ServerStorage = game:GetService("ServerStorage")

-- variables
local Tycoon = script.Parent
local BasePart = Tycoon.BasePart
local Buttons = Tycoon:WaitForChild("Buttons")

Buttons.DescendantAdded:Connect(function(Button)
ButtonSet(Button)
end)

Try this - when a descendant is added it will call the function with the descendant as the Button parameter.

the event isnt firing i added print + what you did

Can you add a print statement on the first line of ButtonSet function?

e.g. print(Button.Name)

It should work it’s weird.

You can check connection too:

local conn = Buttons.DescendantAdded:Connect(ButtonSet)
print(conn.Connected)

image
the button set function works for the 2 parts

It is important to understand and always keep in mind Roblox’s client-server model.

First of all, where exactly is the script located? Secondarily, assuming this is a server script, only descendants added on the server will be detected by the script. How exactly are the “Buttons” being added to the folder? How are you testing this?

2 Likes

it is on server workspace and i am using command bar

Command bar runs locally. That can be a problem like ZEDD mentioned.

2 Likes

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