I’m trying to run a script that copies every tool in a folder in ReplicatedStorage into the user’s backpack upon joining, but the items won’t enter the player’s backpack.
function btools(p)
local tools = game.ReplicatedStorage.Tools
if players:FindFirstChild(p.Name) then
local bag = p:WaitForChild("Backpack")
if bag:FindFirstChild("Stamper Tool") == nil then
for i, tool in ipairs(tools:GetChildren()) do
local copy = tool:Clone()
copy.Parent = bag
print("Copied ",copy," into ",bag)
end
print("Gave tools to ",p)
end
end
end
When the script runs normally it still prints that it copied the tools to the backpack, but they don’t appear in the inventory. I also can’t set the tools to the StarterPack because the player must have a certain role to call the btools function.
I’ve tested the script by setting the copy.Parent to the workspace and the tools copied in without a problem. I also tried using Humanoid:EquipTool to no avail. The game also has a lot of scripts that connect upon the player joining, so could they be slowing down the player loading so much the backpack doesn’t load in time?
Please let me know if you have any possible fixes.
It seems to be able to get the player fine, I was able to assign the tools to startergear instead of the backpack and they loaded in without a problem. Not sure how that works.
-- //Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- //Folders
local Tools = ReplicatedStorage:FindFirstChild("Tools")
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
-- //Remotes
local SendTool = RemoteEvents:FindFirstChild("SendTool")
SendTool.OnServerEvent:Connect(function(player: Player, ...: any)
-- //
for _, obj in ipairs(Tools:GetChildren()) do
if not player.Backpack:FindFirstChild("Stamper Tool") then
-- //Clone
local cloneObj = obj:Clone()
obj.Parent = player.Backpack
print(obj.Name.." inside backpack")
end
end
end)
– //my local works
-- //Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- //Folders
local Tools = ReplicatedStorage:FindFirstChild("Tools")
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
-- //Remotes
local SendTool = RemoteEvents:FindFirstChild("SendTool")
-- //Character
local character = script.Parent or Players.LocalPlayer.Character or Players.LocalPlayer.CharacterAdded:Wait()
-- //Player
local player = Players:GetPlayerFromCharacter(script.Parent)
SendTool:FireServer()