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

Why is Destroy() not working after I clone a Folder?

I am cloning this Folder full of TextLabels into a SurfaceGui. I have a button in the SurfaceGui to remove the Folder with "Destroy()". The Folder never removes when I click the button. (The game is FE)

Cloning Script: --This is a LocalScript

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Parent.ScreenGui.Frame.Visible = true
	wait(0.1)
	local order = game.Players.LocalPlayer.Backpack.Order:Clone()
	order.Parent = game.Workspace.OrderMachine.Order.SurfaceGui.Frame
end)

Destroy Script: --This is a Script

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Order:Destroy()
end)

3 comments

2

Use a remote event to tell the server that the player has clicked the GuiButton. The server should handle destroying and cloning the objects.

1

Cloning an instance on the client wont replicate to the server.

0

Agreed

1 answer

I think I know what it is. See, when you clone the folder with the localscript, only the client sees the folder, not the server. Therefore, when the server tries to destroy it, it can't even find it, so an error pops up. I think this is what you are doing wrong. And considering the game is FE, you have got a BIG problem. So I think you need to use a server script to clone it. I know this might seem hard to do, but you can use RemoteFunctions and RemoteEvents to make the server and client communicate. I bet you will find a way. If this isn't your problem and the server sees it, I don't know what to tell you.

1 comment

0

Alright thank you, this has worked. I totally forgot about Client vs Server since it was cloning into workspace. Thanks for reminding me, lol.

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