If you want to give the player the tool every time they spawn (since the player’s tools get deleted upon respawn), you don’t need a script. All you need to do is parent the tool to StarterPack and it will do the work for you
You could do as suggested by @neweve2323 , but if you’re looking to expand your scripting knowledge, here’s an example with explanation:
-- Server script (Just a normal script)
-- Located in ServerScriptService (optimal location for server scripts)
-- Name it something along the lines of ToolHandler
-- Tool is located in ServerStorage. This is optimal because only the server can access it
local players = game:GetService("Players") -- Get the Players service, which we will use to give each player the tool
local serverStorage = game:GetService("ServerStorage") -- Get the ServerStorage service, which contains our tool
local tool = serverStorage:WaitForChild("ToolX") -- Get our tool from ServerStorage. :WaitForChild() is essentially the same as using the dot operator (.), as in serverStorage.ToolX, however, it won't error if the object doesn't exist for some reason and will yield (wait) until it does
local function playerAdded(player) -- Declare our function for when a player is added to the server. This means a player joined the server. The player parameter, you can name it however you want, but it will be the Player object that joined the game. This function won't work on its own though, we will have to connect it to the players.PlayerAdded connection later
local backpack = player:WaitForChild("Backpack") -- Get the player's backpack. We will insert the tool here
local clone = tool:Clone() -- We are cloning, or duplicating, the tool so that other players can also get a tool. If we use the original tool, this will only work once
clone.Parent = backpack -- Parent the cloned tool to the backpack. Gives the player the tool
end
players.PlayerAdded:Connect(playerAdded) -- Connect our playerAdded function with the players.PlayerAdded connection
Here you go! If you ever wondered, I explained everything and what they tend to do, like @Fizzitix.
-- Make sure you place this script within "ServerScriptService".
-- Reach the Players
local Players = game:GetService("Players")
-- Runs everytime a new player joins the game
Players.PlayerAdded:Connect(function(player) -- The player here is the player that joined. We call them "arguments".
-- Wait until we find the player backpack
repeat wait() until player.Backpack
local tool = Instance.new("Tool") -- Create a new tool, or if you want a specific tool, you could type the path to it in here.
tool.Parent = player.Backpack -- Move the tool to the backpack of the player
end)
If you want to give a Tool to only a specific group of players (or one player) you’ll need to do (this is a server Script inside ServerScriptService):
local list = {
[123456] = true, — change 123456 to the userId of the player
}
local tool = — Where your tool is located
game:GetService("Players").PlayerAdded:Connect(function(player)
if not list[player.UserId] then return end
tool:Clone().Parent = player.Backpack
end
Otherwise if all players get the Tool when they join, just place the Tool inside StarterPack