Child added event is not firing

  1. Im trying to make a admin panel

  2. The child added and removed function are not working

  3. I have put prints trying to detect when a child is added, removed and if that child is a player

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local gui = script.Parent
local Map = gui:WaitForChild("Map")
local Dashboard = gui:WaitForChild("Dashboard")
local Selection = gui:WaitForChild("SelectionArea")
local Players_Panel = gui:WaitForChild("Players")

local OpenMap = Selection:WaitForChild("OpenMap")
local OpenDashboard = Selection:WaitForChild("OpenDashboard")
local OpenPlayers = Selection:WaitForChild("OpenPlayers")

local Image = "https://www.roblox.com/bust-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"

OpenMap.Activated:Connect(function()
	Map.Visible = true
	Dashboard.Visible = false
	Players_Panel.Visible = false
end)

OpenDashboard.Activated:Connect(function()
	Map.Visible = false
	Dashboard.Visible = true
	Players_Panel.Visible = false
end)

OpenPlayers.Activated:Connect(function()
	Map.Visible = false
	Dashboard.Visible = false
	Players_Panel.Visible = true
end)

Map:WaitForChild("ResetMap").Activated:Connect(function()
	RS:WaitForChild("ResetMap"):FireServer()
end)

Map:WaitForChild("RemoveDebris").Activated:Connect(function()
	RS:WaitForChild("CleanUp"):FireServer()
end)

Map:WaitForChild("SillyButton").Activated:Connect(function()
	RS:WaitForChild("Nuke"):FireServer()
end)

Dashboard:WaitForChild("DisplayName").Text = Player.DisplayName
Dashboard:WaitForChild("Username").Text = "@" .. Player.Name
Dashboard:WaitForChild("ProfileImage").Image = Image

Dashboard:WaitForChild("JobId").Text = "Server Id: " .. tostring(game.JobId)
Dashboard:WaitForChild("ServerUptime").Text = "Server Uptime: " .. math.round(time())

task.spawn(function()
	while task.wait(1) do
		Dashboard:WaitForChild("ServerUptime").Text = "Server Uptime: " .. math.round(time()) .. " seconds"
	end
end)

function add(plr: Player)
	print("added")
	
	local new = Players_Panel:WaitForChild("Template"):Clone()
	new.Parent = Players_Panel:WaitForChild("ScrollingFrame")
	new.Name = plr.Name
	new.Visible = true
	new:WaitForChild("Username").Text = plr.Name
end

function remove(plr: Player)
	if Players_Panel:FindFirstChild(plr.Name) then
		print("removed")
		
		Players_Panel:WaitForChild(plr.Name):Destroy()
	else
		warn("couldn't find")
	end
end

Players.PlayerAdded:Connect(function(plr)
	print("player added")
	
	add(plr)
end)

Players.PlayerRemoving:Connect(function(plr)
	print("player removed")
	
	remove(plr)
end)

Output:

just use Players.PlayerAdded and game.Players.PlayerRemoving

I’ve already tried using those and they didn’t work

What do you mean by not working? Are the functions not firing? or are no children being added?

Children are being added, but the child added event itself is not firing, neither is player added

I think that the only child that will be added to the “players” service

Players. -- this one

will be players, so you should you probobaly just do

Players.PlayerAdded:Connect(Function(plr)
        --then inside here you do whatever you want
end)

the functions may not fire because Im not sure players service was made for that! player added is a great alternative.

wait I think I see the problem.

was this made in a local script?

Yes it was made in a local script


there’s the problem! child added does not work on local scripts.

I have changed the script to have PlayerAdded but that doesn’t work, PlayerRemoving is working though

this may happen because if you change it to player added, your asking (if statement) if the thing that joined is a player when you already know it is. So when a player is added, simply run the

add(child) 

function!

Heres the new script

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local gui = script.Parent
local Map = gui:WaitForChild("Map")
local Dashboard = gui:WaitForChild("Dashboard")
local Selection = gui:WaitForChild("SelectionArea")
local Players_Panel = gui:WaitForChild("Players")

local OpenMap = Selection:WaitForChild("OpenMap")
local OpenDashboard = Selection:WaitForChild("OpenDashboard")
local OpenPlayers = Selection:WaitForChild("OpenPlayers")

local Image = "https://www.roblox.com/bust-thumbnail/image?userId="..Player.UserId.."&width=420&height=420&format=png"

OpenMap.Activated:Connect(function()
	Map.Visible = true
	Dashboard.Visible = false
	Players_Panel.Visible = false
end)

OpenDashboard.Activated:Connect(function()
	Map.Visible = false
	Dashboard.Visible = true
	Players_Panel.Visible = false
end)

OpenPlayers.Activated:Connect(function()
	Map.Visible = false
	Dashboard.Visible = false
	Players_Panel.Visible = true
end)

Map:WaitForChild("ResetMap").Activated:Connect(function()
	RS:WaitForChild("ResetMap"):FireServer()
end)

Map:WaitForChild("RemoveDebris").Activated:Connect(function()
	RS:WaitForChild("CleanUp"):FireServer()
end)

Map:WaitForChild("SillyButton").Activated:Connect(function()
	RS:WaitForChild("Nuke"):FireServer()
end)

Dashboard:WaitForChild("DisplayName").Text = Player.DisplayName
Dashboard:WaitForChild("Username").Text = "@" .. Player.Name
Dashboard:WaitForChild("ProfileImage").Image = Image

Dashboard:WaitForChild("JobId").Text = "Server Id: " .. tostring(game.JobId)
Dashboard:WaitForChild("ServerUptime").Text = "Server Uptime: " .. math.round(time())

task.spawn(function()
	while task.wait(1) do
		Dashboard:WaitForChild("ServerUptime").Text = "Server Uptime: " .. math.round(time()) .. " seconds"
	end
end)

function add(plr: Player)
	print("added")
	
	local new = Players_Panel:WaitForChild("Template"):Clone()
	new.Parent = Players_Panel:WaitForChild("ScrollingFrame")
	new.Name = plr.Name
	new.Visible = true
	new:WaitForChild("Username").Text = plr.Name
end

function remove(plr: Player)
	if Players_Panel:FindFirstChild(plr.Name) then
		print("removed")
		
		Players_Panel:WaitForChild(plr.Name):Destroy()
	else
		warn("couldn't find")
	end
end

Players.PlayerAdded:Connect(function(plr)
	print("player added")
	
	add(plr)
end)

Players.PlayerRemoving:Connect(function(plr)
	print("player removed")
	
	remove(plr)
end)

When you run the game, does it print “player added”?

No it does not print player added when run

okay, and is there any error in the output?

No there is no error in output

This may be the problem. Otherwise im not really sure, try testing in the roblox app. I wish you luck!

1 Like