How do i clone tools to player from replicated storage?

I need to make a purchase system that clones a tool from replicated storage. I have some code that is fine for the purchase i just don’t know how to clone the tool to the player.

local clickDetector = script.Parent

clickDetector.MouseClick:Connect(function(player)
local leaderstats = player.leaderstats.Wins.Value
if leaderstats < 1 then
print(“Wins under 1”)
end
if leaderstats >= 1 then
print(“Wins over 1”)
end
end)

Make a Remote Event, this should be done on the server.

-- Server Script
PurchaseEvent.OnServerEvent:Connect(function(player)
   if player.leaderstats.Wins.Value ~= 1 then return print(player.." doesn't have enough wins")
   local Tool = game:GetService("ReplicatedStorage").tools:Clone() -- Just locate the tool and clone it
   Tool.Parent = player.Backpack
end)
2 Likes

I’m kinda dumb and i don’t know where to put the event ik you said server but there’s a bunch.
(mostly because I’m a animator and and not a scripter and i don’t have bobux to pay anyone lol)

So create a folder inside replicatedStorage called "Events" and in there put a remote event called "Purchase" or anything you want.

Now on the client, so where your click detector is do this

--- Client Side
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage.Events.Purchase -- Just defining wherer we put the event
local ClickDetector = script.Parent

ClickDetector.MouseClick:Connect(function()
   PurchaseEvent:FireServer()
end)

Now that should be it for the clients side, now we move onto the server:

-- Server Side
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PurchaseEvent = ReplicatedStorage.Events.Purchase 

PurchaseEvent.OnServerEvent:Connect(function(player)
    if player.leaderstats.Wins.Value ~= 1 then return print(player.." doesn't have enough wins")
    local Tool = game:GetService("ReplicatedStorage").tools:Clone() -- Just locate the tool and clone it
    Tool.Parent = player.Backpack
end)

The reason we do it on the server is because exploiters can’t access it, and the server know the correct amount of wins since an exploiter can easily change the values. Hope this helps.

Can you not just do this entirely from the server anyways?

Yeah, although It might make it easier since he already has a click detector set and a script within it. Also it’s a great way to get introduced into RemoteEvents.