Can someone help me clone a script?

So i’ve made a script that uses remote events and stuff, and it works perfectly fine bu there’s a thing that doesn’t really work.

Server

local players = game.Players

local ReplicatedStorage = game:GetService('ReplicatedStorage')

local PlayerAddedEvent = ReplicatedStorage:WaitForChild('PlayerAdded')

players.PlayerAdded:Connect(function(player)
PlayerAddedEvent:FireAllClients(player.Name)
end)

Client

local gui = script.Parent
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local PlayerAddedEvent = ReplicatedStorage:WaitForChild('PlayerAdded')
local ScrollingFrame = gui.ScrollingFrame
local label = ScrollingFrame.TextLabel

PlayerAddedEvent.OnClientEvent:Connect(function(player)
	for i, v in pairs(ScrollingFrame:GetChildren()) do
		if v:isA('TextLabel') then
			
			v:Clone()
			
		end
	end
end)

For some reason it doesn’t clone the TextLabel.

If someone is willing to help me i’d be very grateful!

Have you set the parent of the clone?

You mean the scrolling frame? I think that is the parent of the Clone

No, for example:

PlayerAddedEvent.OnClientEvent:Connect(function(player)
	for i, v in pairs(ScrollingFrame:GetChildren()) do
		if v:isA('TextLabel') then
			
			v:Clone()
			v.Parent = ScrollingFrame -- This.
		end
	end
end)

yup did that and still there is no cloned TextLabel.

Try printing out the label:

PlayerAddedEvent.OnClientEvent:Connect(function(player)
	for i, v in pairs(ScrollingFrame:GetChildren()) do
		if v:isA('TextLabel') then
			print(v)
		end
	end
end)

If it didn’t print anything, then it doesn’t exist.

Here’s what you’ve done:

v:Clone() -- clone v
v.Parent = ScrollingFrame -- set the parent of v to ScrollingFrame

Here’s what you should be doing:

clone = v:Clone() -- clone v
clone.Parent = ScrollingFrame -- set the parent of the clone to ScrollingFrame
1 Like

Use local on this

local clone = v:Clone() -- clone v
clone.Parent = ScrollingFrame -- set the parent of the clone to ScrollingFrame
2 Likes

Yup it successfully printed the TextLabel.

Whoops :sweat:

2 Likes

Yup it actually worked!
Thank you very much