Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to call method 'Clone' (a nil value)?

I am working on an Options Gui, and I have just ran into this error while trying to script a mute chat script.

Everything Here is in a Local Script

Here is what is necessary for you to know:

local options = script.Parent.Options
local muteChatVar = script.Parent.Options.MuteChatSwitch
local chatSwitch = options.MuteChatFlip.Switch

local playerGui = player:WaitForChild("PlayerGui")
local playerStats = playerGui:WaitForChild("PlayerStats")
local chatFrame = playerStats:WaitForChild("Chat")
local chats = chatFrame:GetChildren()

chatSwitch.MouseEnter:connect(function(onEnter)
	wait(0.03)
	enterS:Play()
end)
chatSwitch.MouseButton1Click:connect(function(onClicked)
	wait(0.03)
	clickS:Play()
	if muteChatVar.Value == "Off" then
		chatSwitch:TweenPosition(UDim2.new(0, 0, 0, 0), "In", "Quint", 0.5)
		muteChatVar.Value = "On"
		chats:Clone()
		chats:Clone().Parent = replicatedStorage.Chats
		chats:Remove()
	elseif muteChatVar.Value == "On" then
		chatSwitch:TweenPosition(UDim2.new(0.5, 0, 0, 0), "Out", "Quint", 0.5)
		muteChatVar.Value = "Off"
		local newchats = replicatedStorage.Chats:GetChildren()
		newchats:Clone()
		newchats:Clone().Parent = chatFrame
	end
end)

All help is appreciated! Comment below if you need any more information about it!

1 comment

0

The error is for line 20,21 and 27,28

1 answer

✓ Accepted answer

GetChildren returns a list. You can't clone a list.

What you need to do is loop through the list with a for loop, cloning each individual item. For example,

for index, value in ipairs(x:GetChildren()) do
	value:Clone().Parent = y
end

However, since you're getting the children from an object in ReplicatedStorage, you may be able to just clone that Parent object directly:

replicatedStorage.Chats:Clone()

Another note to make,

newchats:Clone()
newchats:Clone().Parent = chatFrame

is a bad practice. If you look at it, you'll notice that you're actually calling Clone() two times, meaning the object gets cloned two times. However, you're only using one of those clones.

Change it to either

newchats:Clone().Parent = chatFrame

Or

local cloned = newchats:Clone()
cloned.Parent = chatFrame

2 comments

0

Thank you! However it still doesn't clone the chat pieces even with everything you gave me to try. It still gives me the clone error.

0

Can you post your new code somewhere, please

This discussion is preserved as it was. New answers, comments, and votes are closed.