Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i clone a tool in my backpack?

Asked by 4 years ago

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()

0
try waiting beforehand. proqrammed 285 — 4y
0
Wait, a localscript or a server script. You can only get the localplayer from a localscript. proqrammed 285 — 4y
0
You cant use localplayer in a normal script and by cloneing it with a local script only you will see it EnzoTDZ_YT 275 — 4y
1
and this is not a request site EnzoTDZ_YT 275 — 4y
0
i'm pretty sure this is just asking for a solution, and also remember that localscripts dont run in workspace, browniexpoptxrt proqrammed 285 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Answer this question