Hello there, right now I’m currently going mad. I have this snippet of server-sided code, which is supposed to clone weapons from ReplicatedStorage and parent them to the player’s backpack. However, It just out of the blue decided not to work anymore. I did some work on a loadout system, which uses a bindable event. The way the loadout system works is that it’s basically a library of ImageButtons, and when you click on it, your backpack gets cleared. However that should only happen if it is clicked. I tried parenting the clones to workspace, it worked but after a bit they disappeared. I checked everyone of my scripts and nothing seems wrong. I created a new script just for cloning the weapons, it worked for one run. Then it stopped working again. The code that clones the weapons and parents them to the backpack, uses a folder that is Instanced.new’d in the game.Players.PlayerAdded, which is basically a collection of 3 string values, (Primary, Secondary, And Melee) which determine the loadout that the player is using.
Here’s that snippet of code.
for i, v in pairs(loadout:GetChildren()) do
game.ReplicatedStorage.Weapons.MainWeapons[v.Name][v.Value]:Clone().Parent = plr.Backpack
end
It looks pretty straight forward, I know. But I can’t find for the love of god why it destroys tools when a player is added.
If you know why this keeps breaking please let me know, and possibly how to solve it.
I would recommend adding print statements to your code to monitor the behavior:
game.Players.PlayerAdded:Connect(function(plr)
local backpack = plr:WaitForChild("Backpack")
local loadout = Instance.new("Folder") -- Replace this with the correct loadout retrieval method
loadout.Parent = plr
-- Add your string values (Primary, Secondary, Melee) to the loadout folder here
for i, v in pairs(loadout:GetChildren()) do
print("Cloning weapon:", v.Name, v.Value)
local clonedWeapon = game.ReplicatedStorage.Weapons.MainWeapons[v.Name][v.Value]:Clone()
clonedWeapon.Parent = backpack
print("Weapon cloned and parented to backpack:", clonedWeapon.Name)
end
-- Print the content of the player's Backpack
print("Backpack content for player:", plr.Name)
for _, tool in pairs(backpack:GetChildren()) do
if tool:IsA("Tool") then
print(tool.Name)
end
end
end)
It will help you monitor the cloning process and the state of the player’s backpack. If you find that the tools are being destroyed when the player is added, you might want to check other scripts in your game to see if anything is clearing the backpack unintentionally.
It seems that it just deletes itself after the cloning. Everything is cloned and printed properly in the console. Is there a way that I can check every script? I know it’s server sided so I only need to look at normal scripts.
It seems that something else in your game is affecting the tools in the player’s backpack. You can try searching for the script that modifies the player’s backpack among your server-side scripts.
Simply search for “Script” in the Explorer tab and inspect all the scripts you have for that place.
Ok, So I searched up “Script”, checked every server sided script once more, I searched for words like “backpack” or “tool” but I came up empty handed. It’s weird that all of this started happening when I implemented the loadout system properly. I’ll have to take a look at those scripts. But then again most of those scripts are local scripts, which wouldn’t explain why the tools just delete itself. It’s confusing, and I don’t know why it happens.
I’ll check those loadout scripts, maybe disable them to see if any of them affect the tools deleting itself or not.
Edit: Nope, nothing.
I guess I should also mention that I disabled nearly every script, to no avail. I work with a friend, I asked them if they did anything and they said no.
Sorry for the late response, as I was sleeping. But in the scripts I have searched for “Backpack” or “Tool”. To no avail. I guess it’s important to know that I parented the cloned weapons to workspace for debugging, It worked, but then they get destroyed.
As I said previously, I did add that snippet of code to its own separate script in ServerScriptService. It worked for one run. ONE RUN. Then it stopped working again.
Hey man, I was having this issue too.
You probably are loading the character after cloning the tools. Make sure you don’t run any Player:LoadCharacter after you added things to the backpack since this will refresh it. This worked for me anyways.
There aren’t any LoadCharacter()'s in the script, The script is basically a script that does this when a player is added, like Instance.new’ing folders and such.