I am making a phone in game and I want it so that when a new player joins, everyone gets “their” contact on their message app. When I test it, nobody comes up?
local players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
for _, players in pairs(players:GetPlayers()) do
if not players.Name == player.Name then
local scrollingFrame = players.PlayerGui:WaitForChild("Phone").Frame.Main.Messages.ScrollingFrame
local template = players.PlayerGui:WaitForChild("Phone").Frame.Main.Messages.ScrollingFrame.TemplateFolder.Template:Clone()
template.Name = player.Name
template.Text = player.Name
template.Visible = true
template.Parent = scrollingFrame
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
for _, players in pairs(players:GetPlayers()) do
if not players.Name == player.Name then
local scrollingFrame = players.PlayerGui:WaitForChild("Phone").Frame.Main.Messages.ScrollingFrame
local plr = scrollingFrame:FindFirstChild(player.Name)
if plr then
plr:Destroy()
end
end
end
end)
I changed it, but nothing pops up for any player? I tested with 3 players in a local server and the message app showed nobody in the list?
local players = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
for _, plr in pairs(players:GetPlayers()) do
if not plr.Name == player.Name then
local scrollingFrame = plr.PlayerGui:WaitForChild("Phone").Frame.Main.Messages.ScrollingFrame
local template = plr.PlayerGui:WaitForChild("Phone").Frame.Main.Messages.ScrollingFrame.TemplateFolder.Template:Clone()
template.Name = player.Name
template.Text = player.Name
template.Visible = true
template.Parent = scrollingFrame
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
for _, plr in pairs(players:GetPlayers()) do
if not plr.Name == player.Name then
local scrollingFrame = plr.PlayerGui:WaitForChild("Phone").Frame.Main.Messages.ScrollingFrame
local plrr = scrollingFrame:FindFirstChild(player.Name)
if plrr then
plrr:Destroy()
end
end
end
end)