Why do I keep getting errors with :Clone()

1st attempt

I’m a bit confused, I am trying to make a button and if they say yes, it clones the tool and puts it into starterpack.

script.Parent.MouseButton1Click:connect(function()
	local rs = game:GetChildren("Lighting")
	local SP = game:GetChildren("StarterPack")
	local Key = rs.Key
	local clone = Key:Clone()
	clone.Parent = SP
	script.Parent.Parent.Parent:Destroy()
end)

second attempt
For this I tried making an event but it still gave the same error.

local event = game.ReplicatedStorage.KeyEvent

script.Parent.MouseButton1Click:connect(function()
	event:FireServer()
	script.Parent.Parent.Parent:Destroy()
end)

server

game.ReplicatedStorage.KeyEvent.OnServerEvent:connect(function(player)
	local rs = game:GetChildren("Lighting")
	local SP = game:GetChildren("StarterPack")
	local Key = rs.Key
	local clone = Key:Clone()
	clone.Parent = SP
end)

Try cloning the tool out of replicated storage Also, Do you want it to give it to the player right away? If you clone it to starter pack they will have to reset. If you want them to have it right away then you should clone it to player.Backpack

What error are you receiving? Would help.

I do not understand why you are using :GetChildren() when that would return a table instead of a singular instance, I normally don’t spoonfeed code but I will do it this time to help you out and explain to you what you did wrong.

Client:

local BUTTON = script.Parent

local RE = game.ReplicatedStorage.Folder:WaitForChild(“RemoteEvent”)

BUTTON.MouseButton1Down:Connect(function(player)

print(“button was clicked”)

RE:FireServer()

end)

Server:

local tool = game.ReplicatedStorage.Folder:WaitForChild(“Tool”)
local RE = game.ReplicatedStorage.Folder:WaitForChild(“RemoteEvent”)

game.Players.PlayerAdded:Connect(function(player)
RE.OnServerEvent:Connect(function()
tool:clone().Parent = player.Backpack — clones the tool and puts in the player’s backpack
end)
end)

Make sure you use the client to detect the button was clicked and make the server do the legwork(clone the tool).

anways I hope this helped

1 Like

I’m thinking you use :GetChildren() instead of :GetService(), lol make sure you don’t make that mistake again.

2 Likes

May I know why you are storing your tool in the lighting class?

Doesn’t matter, the Lighting service is accessable from the client

Alright, but why 3 months later?

Its best if you place tools in ReplicatedStorage, which is easily accessible for both Server and Client. I dont really get why some people place their tools in Lighting. ReplicatedStorage is the proper service you place tools and other objects in.

does not matter where it’s stored as long as it can be accessed from both the client or server, most people use ReplicatedStorage (myself included) but lighting will work just fine so it does not matter.