Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does ChildAdded not work when a model goes into another model?

Asked by
thePyxi 179
4 years ago

This is a ServerScript in ServerScriptService, There are models called "Room1", "Room2", etc, in Replicated Storage. The Rooms are cloned into the model of GameRooms. But, when the clones do go into GameRooms, the function of ChildAdded does not work. Nothing gets printed.

local GameRooms = game.Workspace.GameRooms
local RoomNumber --(RoomNumber is IntValue found in player's leaderstats)

GameRooms.ChildAdded:Connect(function(Added)
    print(Added)
    if Added.Name == "Room"..RoomNumber.Value then
        local Room = Added.Name
        local Button = GameRooms[Room].Button
        local ClickDetector = Button.ClickDetector
        ClickDetector.MaxActivationDistance = 7

        local Door = GameRooms[Room].Door

        ClickDetector.MouseClick:Connect(function()
            Click(Door)
        end)
    end
end)

Answer this question