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