How would I clone a tool from ServerStorage into the player that clicked the ClickDetector, into a the player’s backpack?
1 Like
ClickDetector.MouseClick:Connect(function(plr)
local tool = game.ServerStorage.Tool:Clone()
tool.Parent = plr.Backpack
end)
6 Likes
local clickDetector = workspace.Part.ClickDetector
local function onMouseClick()
local clonetool = game.ServerStorage.TestTool:Clone()
local name = game.Players.LocalPlayer.Name
clonetool.Parent = game.Players[name].Backpack
end
clickDetector.MouseClick:connect(onMouseClick)
add a solution if this helped.
1 Like
Try putting a script inside the “Handle” and put this script in
local tool = script.Parent.Parent
local click = script.Parent.ClickDetector
local function pickup(player)
tool.Parent = game.Workspace[player.Name]
end
click.MouseClick:Connect(pickup)
2 Likes
You should use replicated storage. Put the tool in a folder under replicated storage. Here is an example script from my shop script:
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function(click)
if player.leaderstats.Coins.Value >= 50 then
player.leaderstats.Coins.Value=player.leaderstats.Coins.Value-50
game.ReplicatedStorage.Swords.CopperGreat:Clone().Parent = player:WaitForChild("Backpack")
end
end)
Edit: Sword is the name of the folder, CopperGreat is the tool.
2 Likes
The other players wont see the tool.
1 Like
ya I just realised that I misread the discussion question my bad.
1 Like
Simple as this:
script.Parent.Activated:Connect(function(player)
game.ServerStorage.Tool:Clone().Parent = player.Backpack
end)
1 Like
It is better if you clone the tool from ReplicatedStorage rather than ServerStorage, since it is accessible through both scripts. However it could do.
local CD = game.Workspace.Part.ClickDetector
CD.MouseButton1Click:Connect(function(player)
local tool = game.ServerStorage["Tool"] --game.ReplicatedStorage can work also
tool:Clone().Parent = workspace[player] --or player.Backpack
end)
1 Like
Reading through all of these now
This works perfectly and is simple. Thanks