This script gives a player 3 tools, but I get "___ is not a valid member of Folder", even though the specified tool is a member of Folder

Hi! This script is supposed to give a player 3 items, but I get the error “Vanilla Cakepop is not a valid member of Folder”. Item1, Item2, and Item3 all return “Vanilla Cakepop”. FinishedItems is a folder in ServerStorage. There is a tool in FinishedItems called Vanilla Cakepop, so idk why it is giving me this error. Here is the script:

game.ReplicatedStorage.GivePlayerOrder3.OnServerEvent:Connect(function(Chef, Item1, Item2, Item3, Customer)
	local finishedFolder = game.ServerStorage:FindFirstChild("FinishedItems")
	if game.Players:FindFirstChild(Customer) then
		local clone1 = finishedFolder[tostring(Item1)]:Clone()
	clone1.Parent = game.Players[Customer].Backpack
	local clone2 = finishedFolder[tostring(Item2)]:Clone()
	clone2.Parent = game.Players[Customer].Backpack
	local clone3 = finishedFolder[tostring(Item2)]:Clone()
		clone3.Parent = game.Players[Customer].Backpack
		print("3 items given to customer: " .. Customer)
	else
		print("Unfortunately, player left.")
	end
	
	
end)

You can try using :WaitForChild instead of directly thinking its there.

Can you show a picture of your explorer? It might not replicate right away, or it might not have that exact name, but it’s hard to tell without more context.

2 Likes

WaitForChild didn’t do anything, because it couldn’t find the child or the child returned nil probably

Screenshot (60)

1 Like

Maybe the script that fires the event is wrong?

This is the localscript that fires the event

script.Parent.MouseButton1Click:Connect(function()
		local amountSplit = string.split(script.Parent.Parent.AmountOfItemsCorrect.Text, "/")
if amountSplit[1] == amountSplit[2] then
		local orderSplit = string.split(script.Parent.Parent.Order.Text, ", ")
		local CustomerSplit = string.split(script.Parent.Parent.Customer.Text, "ustomer: ")
		local Customer = tostring(CustomerSplit[2])
	
		
			if #orderSplit == 3 then
			
			game.ReplicatedStorage.GivePlayerOrder3:FireServer(tostring(orderSplit[1]), tostring(orderSplit[2]),  tostring(orderSplit[3]), Customer) --this line of code fires the event
		
			end
			if #orderSplit == 2 then
			
			game.ReplicatedStorage.GivePlayerOrder2:FireServer(tostring(orderSplit[1]), tostring(orderSplit[2]), Customer)
			
			end
			if #orderSplit == 1 then
			
			game.ReplicatedStorage.GivePlayerOrder1:FireServer(tostring(orderSplit[1]), Customer)
			
			end
			
		
		
	else
		print("Not all items made!")
	end
	
	
end)

I agree with the others. Try using WaitForChild at the top of the script so that you know everything loaded in.

I used waitforchild(), but the script didn’t do anything when i did.

? What do you mean by ‘(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)’?

It means I deleted my comment - I replied telling you that serverstorage can’t be used in a localscript but then I realized you had said it was a normal script.

Oh, okay. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

I think your Customer Splitting might be wrong, you could try printing it out to be sure though.

Try removing the tostring in the server script.
I don’t know if this is the solution, but it may be.
Sorry if I messed up.
Have a nice day.

Instead of doing WaitForChild() try doing WaitForChildOfClass(“classname here!”)

It’s okay, I found out that it was returning “Order: Vanilla Cakepop” instead of “Vanilla Cakepop”. But thanks for your help.