So I'm making a weapon select GUI with one master script for each category of weapons that gives you the weapon you want, if you have enough points for it, and it does this for each button, as long as the options inside them exist. So far, it works perfectly, except for one thing. Clicking the button clears your player's StarterGear and puts the new weapon inside it, so you get the weapon next time you respawn. It works fine with singleplayer testing, but in a server, it doesn't give me my startergear tools when I spawn in, even though it does put the weapon in there, handle and everything. Is this a problem with my script, or a problem with roblox? Here's the part of my script that puts the weapon in your player's startergear, where weapon is a variable for the button's "Weapon" ObjectValue, which links to a tool in ReplicatedStorage
local startergears = player.StarterGear:GetChildren()
for i = 1, #startergears do
startergears[i]:Destroy()
end
local newweapon = weapon.Value:Clone()
newweapon.Parent = player.StarterGear
I really hope this isn't a problem with Roblox, because other than startergear, I have no idea how to make the weapon you've selected save after you die, and I don't want my players to have to select the weapon again everytime they respawn by putting the weapon in their backpack. If you need need more of my script, please let me know.

8 comments
This is a server side script, correct? Also, you are  absolutely sure the tool in ReplicatedStorage exists, right? ObjectValues link to an object, they do not store an object.
Yes, it exists. I put the tools in there in studio, and the menu puts the items in your startergear as it should. The problem isn't with the menu giving you weapons, but with your startergear giving you the weapons when you spawn. It's a localscript inside the GUI and filtering isn't enabled.
Why not use StarterPack?
Also, just for a nitpick, you can use the :ClearAllChildren() method instead of your for loop. Just a way to reduce number of lines of code you have.
Wait a minute, why was I using that loop? I know how ClearAllChildren works, I don't know why I didn't just use that lol. Also, if it put it into starterpack, that would change the weapon every player spawns with. I only want the player who selected the weapon to spawn with it.
Now that I think about it, I could just make a simple loop to clone your startergear to your backpack each time you spawn as a temporary solution to this. I'll try that now.
My cloning loop worked! It's probably not the best solution, but it'll do for now.
idk what happened but I made the game filteringenabled and now it doesn't even need a loop :D