Can't clone objects. Always come out as nil

I’m having a problem where any object I clone is coming out as nil. In this case I am trying to clone a gui that is stored in replicated storage (RS) and parent it to a part (bait) that is stored in a folder in the workspace.

Server Script:

function CreateBaitUI(bait)
	local ExampleUI = RS:WaitForChild("Bait_Arrow"):Clone()
	ExampleUI.Parent = bait
	ExampleUI.Adornee = bait
	ExampleUI.Enabled = false
	
	return ExampleUI
end

A remote event is fired just after the ui in the function above is meant to be cloned.

Now in this local script I am trying to use this cloned ui and make it visible and move up and down for one player.

Local Script:

ShowArrow_EV.OnClientEvent:Connect(function(bait_Ui)
	local Tin = TweenInfo.new(
		1,
		Enum.EasingStyle.Cubic,
		Enum.EasingDirection.InOut,
		-1,
		true,
		0
	)
	
	**local T = TS:Create(bait_Ui:FindFirstChild("Arrow_Img"), Tin, {Position = UDim2.new(0, 0, 0, 0)})**
	bait_Ui.Enabled = true
	T:Play()
end)

Every time I try to use this I get this error on the line with asterixs either side of in the local script:
“attempt to index nil with ‘FindFirstChild’”

Any help would be appreciated!

5 Likes

Have you tried replacing the RS:WaitForChild("Bain_Arrow"):Clone() to FindFirstChild?

yes i have i get the same error

When you are firing the remote event to the client, I’m guessing you’re passing the player and the data right? Just making sure.

1 Like

yes i am
image
EDIT: Forgot to add, im sending baitUi because the returned ui is assigned as baitUi
image

2 Likes

Debug Scripts


I want you to run these few scripts so I can detect where it doesn’t find the clone.
Please send back the orange text in the output!

-- Run below function CreateBaitUI(bait)
warn("Cloning Object: "..RS:FindFirstChild("Bait_Arrow"))
warn("Cloned the object: "..ExampleUI)

-- Run below ShowArrow.OnClientEvent
warn("Checking bait_UI: "..bait_UI})
warn("Checking Arrow_Img: "..bait_UI:FindFirstChild("Arrow_Img"))
1 Like

It shows this error:

image

2 Likes

Oh, my bad forgot to add .Name to all the objects

-- Run below function CreateBaitUI(bait)
warn("Cloning Object: "..RS:FindFirstChild("Bait_Arrow").Name)
warn("Cloned the object: "..ExampleUI.Name)

-- Run below ShowArrow.OnClientEvent
warn("Checking bait_UI: "..bait_UI.Name)
warn("Checking Arrow_Img: "..bait_UI:FindFirstChild("Arrow_Img").Name)
1 Like

Gets through the 2 in the server function but errors on the local script:

image

Alright, it appears as though the server is receiving it fine but not the client. So we’re going to have to focus on where you have sent the object.

image
Maybe try adding debug prints to detect if the variable baitUi is not nil. (The one where you fire the event)

1 Like

Added one just after creating the ui:
image
And it does show:
image

EDIT: Also just added one under where the event fires:
image
And it is still not nil:
image

Is anything else firing that remote event?

Nope, that is the only point the event is fired

Wait a minute,
image
I just noticed you spent bait_Ui with a lowercase

-- Run below ShowArrow.OnClientEvent
warn("Checking bait_UI: "..bait_Ui.Name)
warn("Checking Arrow_Img: "..bait_Ui:FindFirstChild("Arrow_Img").Name)

Yeah I noticed you did capital and changed it already

To what exactly are you parenting the ExampleUI?

image
I did some testing and found that objects that are parented to nil will be nil through events.

I said in the original post, it’s being parented to a part stored in a folder in the workspace.

1 Like

I just tried printing its parent and its nil :thinking:

I think we found our bug perhaps