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

How do i clone a tool in my backpack?

so i am making a script and i dont know how to clone it cause i just did :Clone() and nothing is working game:GetService("Players").LocalPlayer.Backpack.M9:Clone()

5 comments

0

try waiting beforehand.

0

Wait, a localscript or a server script. You can only get the localplayer from a localscript.

0

You cant use localplayer in a normal script and by cloneing it with a local script only you will see it

1

and this is not a request site

0

i'm pretty sure this is just asking for a solution, and also remember that localscripts dont run in workspace, browniexpoptxrt

2 answers

✓ Accepted answer

You can either use the PlayerAdded event from game.Players or fire a RemoteEvent or RemoteFunction with a localscript.

Option 1: PlayerAdded

game.Players.PlayerAdded:Connect(function(plr)
  local backpack = plr:WaitForChild("Backpack");
  local tool = game.ReplicatedStorage.Tool:Clone(); -- Change this to the tool location
  local ctool = tool:Clone();
  ctool.Parent = backpack;
end

Option 2: A: RemoteEvent

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr) -- change to the location of your RemoteEvent.
local backpack = plr:WaitForChild("Backpack");
  local tool = game.ReplicatedStorage.Tool:Clone(); -- Change this to the tool location
  local ctool = tool:Clone();
  ctool.Parent = backpack;
end)

Option 2: B: RemoteFunction

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(plr)
local backpack = plr:WaitForChild("Backpack");
  local tool = game.ReplicatedStorage.Tool:Clone(); -- Change this to the tool location
  local ctool = tool:Clone();
  ctool.Parent = backpack;
  return true; -- This is really the only reason you'd use RemoteFunction ;- to return something after it executes to the client who called it.
end

EDIT: I just saw that you wanted to clone the tool in the player's backpack, in which case you'd use Option 2 (either A or B, whichever you think would help more). You'd want to clone the tool in backpack instead of the one in ReplicatedStorage.

If you want to clone a tool in your backpack, first we need to get the local player since the player's backpack is locally based.

player = game.Players.LocalPlayer

Next, we need to actually type the script that clones the tool in your backpack and puts it in your backpack again.

player.Backpack.M9:Clone().Parent = player.Backpack

So in the end, this is the final script:

player = game.Players.LocalPlayer

player.Backpack.M9:Clone().Parent = player.Backpack

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