I want to make it so that when a player’s friend goes offline the template of his friend gets destroyed.
local player = game.Players.LocalPlayer
local friends = player:GetFriendsOnline(20)
for i, friend in pairs(friends) do
if friend.IsOnline == true then
if not script.Parent:FindFirstChild(friend.UserName) then
local frame = script.Parent.Parent.FriendTemplate:Clone()
frame.Parent = script.Parent
frame.PlayerName.Text = friend.UserName
frame.Name = friend.UserName
frame.Visible = true
end
end
end
putting it in a loop would be probably the best way
local player = game.Players.LocalPlayer
local ClearFrames = function()
for i,v in pairs(script.Parent:GetChildren()) do
if (v:IsA("Frame")) then
v:Destroy()
end
end
end
task.spawn(function()
while true and task.wait(10) do
ClearFrames()
for i,v in pairs(player:GetFriendsOnline(20)) do
if (v.IsOnline == true) then
local Frame = script.Parent.Parent.FriendTemplate:Clone()
Frame.PlayerName.Text = v.UserName
Frame.Name = v.UserName
Frame.Visible = true
Frame.Parent = script.Parent
end
end
end
end)