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

Why won't this clone?

I made this really simple script, but it's not working.

local backpack = game.Players.LocalPlayer.BackPack
script.Parent.Touched:connect(function()
	game.Lighting.Sword:Clone(backpack)
end)

Help?

5 answers

You have to set the parent;

game.Lighting.Sword:Clone().Parent = backpack
local backpack = game.Players.LocalPlayer.Backpack
script.Parent.Touched:connect(function()
    modelcopy=game.Lighting.Sword:Clone()

modelcopy.Parent=backpack
end)

2 comments

0

One error you had is you said "BackPack" but it needs to be "Backpack"

1

Neither of yours work, I don't know what's going on! Wait, is it because it doesn't work in test?

local backpack = game:service("Players").LocalPlayer.Backpack
--script.Parent.Touched:connect(function()
game:service("Lighting"):FindFirstChild("Sword"):Clone().Parent=backpack
--end)

1 comment

1

Hmm, I don't know why but, none of these work! Sorry.

Try this. Make sure you put it in the part that gives the sword.

local sword = game.Lighting.Sword
script.Parent.Touched:connect(function(h)
    local player = game.Players:GetPlayerFromCharacter(h.Parent) -- find the player from the character

	if (player) then
		-- a player touched it
		
		local clone = sword:Clone()
		clone.Parent = player.Backpack -- parent the clone to the player's backpack
	end
end)

script.Parent.Touched:connect(function(p)
	p = game.Players:GetPlayerFromCharacter(p.Parent)
	if p then
		game.Lighting.Sword:Clone().Parent = p.Backpack
	end
end)

There you go!

5 comments

0

Put this in Local Script. That's why none of these work. You didn't put it on Local Script

0

I did put it in a localscript.

0

Oh.. Well...... Are you putting it in a brick?

0

Oh and..... Do you have a object named "Sword"? It has to have capital.

0

Fixed it.

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