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
I’ve looked in documentation and the dev forum, found nothing.
-- services
local ServerStorage = game:GetService("ServerStorage")
-- variables
local Tycoon = script.Parent
local BasePart = Tycoon.BasePart
local Buttons = Tycoon:WaitForChild("Buttons")
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?