Hello, this is my first devforum post so correct me if im wrong on anything.
My issue is that my script in serverscriptservice is not parenting my tool from replicatedstorage into the player’s backpack upon a playeradded event and the print fires even without the tool being in the backpack.When parenting to workspace it works as intended.
I looked for similar posts on the devforum but could only find ones that parented tool to the backpack after a touched event.
The Script:
local Handgun = game.ReplicatedStorage.Handgun
game:GetService("Players").PlayerAdded:Connect(function(plr)
local GunCopy = Handgun:Clone()
GunCopy.Parent = plr:WaitForChild("Backpack")-- When i tried parenting to workspace it worked normally--
print("cloned")
end)
It is possible that the gun isn’t archivable. Select the gun and go into the properties, enable “Archivable”. This will allow it to be cloned; without it, cloning isn’t possible.
Try just changing the parent of the original model instead of cloning it. If you really need to clone it you can clone the original model outside of the player added back to serverstorage.
When a player joins, the character isn’t immediately added; however, the script immediately runs. This causes the gun model to be cloned and parented to the backpack, but shortly after the character loads. The gun is then deleted since there is a “new” character.
Here’s the solution:
plr.CharacterAdded:wait()
Add this to the line before you set the parent of the gun model.