You should not be directly modifying the Player’s backpack from a LocalScript, as it can cause some tools to error out. Instead, replace the buttons in the LocalScript so that they fire a RemoteEvent:
local remoteEvent = game.ReplicatedStorage:WaitForChild(“ItemEvent”)
script.Parent.MouseButton1Click:Connect(function()
remoteEvent:FireServer(“Cone”) -- Sends the argument of which tool the Player is trying to get through the RemoteEvent.
end)
And on a ServerScript:
local rs = game:GetService(“ReplicatedStorage”)
local remoteEvent = rs:WaitForChild(“ItemEvent”)
remoteEvent:OnServerEvent:Connect(function(Player, toolName)
local isToolGiven = Player.Character:FindFirstChild(toolName) or Player.Backpack:FindFirstChild(toolName) -- Checking if tool is already given.
if not isToolGiven then
local tooltoGive = rs:FindFirstChild(toolName)
local toolClone = tooltoGive:Clone()
toolClone.Parent = Player.Backpack
end
end)
If you want to make it such that the Script swaps tools, do this for the ServerScript:
local rs = game:GetService(“ReplicatedStorage”)
local remoteEvent = rs:WaitForChild(“ItemEvent”)
remoteEvent:OnServerEvent:Connect(function(Player, toolName)
local isToolGiveninCharacter = Player.Character:FindFirstChild(toolName)
local isToolGiveninBackpack = Player.Backpack:FindFirstChild(toolname)
if isToolGiveninCharacter then
isToolGiveninCharacter:Destroy()
end
if isToolGiveninBackpack then
isToolGiveninBackpack:Destroy()
end
local tooltoGive = rs:FindFirstChild(“ToolNameHere”) -- Edit to the name of the tool you want to give.
local toolClone = tooltoGive:Clone()
toolClone.Parent = Player.Backpack
end)