How do i get a tool out of serverstorage and into the players toolbar


i am struggling to figure out the code to get this “Gun” into the players toolbar.

i want it where when they touch the part the tool comes out of server storage and into the players toolbar. and when they leave it goes back into sever storage.

my code so far

i just don’t know the code for getting it out of serverstorage and into the players toolbar. then back out.

i tried looking for youtube videos about it but they all lead into different things about tools.

thank you

1 Like

could you send me the code so I can easily edit it, thanks

Read through the following code I have added comments to try and help:

-- Variables
local Area = script.Parent
local build = false
local gun1 = game.ServerStorage.gun

-- Main
  if hit.Parent:FindFirstChildWhichIsA("Humanoid") and hit.Name == "HumanoidRootPart" then  -- Check that the hit part is a player and the HRP

    gun1:Clone().Parent = game.Players:GetPlayerFromCharacter(hit.Parent).Backpack    -- Clone the tool

-- This is the event for detecting when players leave the area.
  -- Detect if a player has left the area.
  if hit.Parent:FindFirstChildWhichIsA("Humanoid") and hit.Name == "HumanoidRootPart" then

    if hit.Parent:FindFirstChildWhichIsA("Tool") then
      -- Unequip all the players tool to put them inside the backpack.
    -- Destroy the players gun

game.StarterPack.gun1 doesn’t work, as your trying to clone it to the player.

instead, you should have your player variable as your GetPlayerFromCharacter function, then from there, preform the necessary checks to ensure that there is a player, then clone the tool.

local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- Get player

if player then -- Check if it is a player 
    game.ServerStorage.gun1:Clone().Parent = player.Backpack -- if it is, then clone the tool