Frame not cloning at all

Basically I have a frame which clones it self for every player found on a certain team however it’s not working at all heres my script:

local path = game:GetService("Players")

for i, v in pairs(path:GetChildren()) do

if v:IsA("Player") then

if v.Team == teamwhilisted then

local currentofficersreplication = game:GetService("ReplicatedStorage").CurrentOfficerReplication:Clone()

currentofficersreplication.Parent = scrollingframe

currentofficersreplication.Callsign.Text = v.Name

end

end

end

use print and see the output to debug

local path = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
for i, v in pairs(path:GetChildren()) do
    print(v.Team, teamwhilisted, v.Team == teamwhilisted)
    if v.Team == teamwhilisted then
        local currentofficersreplication = RS.CurrentOfficerReplication:Clone()
        currentofficersreplication.Parent = scrollingframe
        currentofficersreplication.Callsign.Text = v.Name
    end
end
1 Like

works now however it doesnt update when someone joins or leaves

1 Like

then u will have to use PlayerAdded and PlayerRemoving event
to the code above or yours add this

-- path is 'game:GetService("Players")'
path.PlayerAdded:Connect(function(Player)
    if Player.Team == teamwhilisted then
        local currentofficersreplication = RS.CurrentOfficerReplication:Clone()
        currentofficersreplication.Parent = scrollingframe
        currentofficersreplication.Callsign.Text = v.Name
    end
end)
path.PlayerRemoving:Connect(function(Player)
    -- what it has to do when the  player leaves
end)

Heres my updated script for some reason when the player leaves instead of destroying the clone it destroys the whole GUI.


local path = game:GetService("Players")
path.PlayerAdded:Connect(function(Player)
	for i, v in pairs(path:GetChildren()) do
		print(v.Team, teamwhilisted, v.Team == teamwhilisted)
	if Player.Team == teamwhilisted then
		local currentofficersreplication = RS.CurrentOfficerReplication:Clone()
		currentofficersreplication.Parent = scrollingframe
		currentofficersreplication.Callsign.Text = v.Name
	end
	end
end)

local path = game:GetService("Players")
path.PlayerRemoving:Connect(function(Player)
	for i, v in pairs(path:GetChildren()) do
		print(v.Team, teamwhilisted, v.Team == teamwhilisted)
		currentofficersreplication:Destroy()
	end
	
end)

there is no need to destroy gui when the player leaves the game because it gets removed within the player but here you go

path.PlayerRemoving:Connect(function(Player)
	for i, v in pairs(path:GetChildren()) do
		print(v.Team, teamwhilisted, v.Team == teamwhilisted)
		Player.PlayerGui.currentofficersreplication:Destroy() -- change to the actuall path
		-- 'currentofficersreplication:Destroy()' destroys the original one
	end
end)

havent noticed that

there is no need to do for loop inside PlayerAdded connected function because it will add another duplicate to players that already have it