Gun not replicating into backpack?

So I have a gun in replicated storage, it’s just a tool with a handle and another part named “Barrel” inside of it. Here’s the local script which is located in StarterPlayerScripts

local players = game:GetService("Players")
local plr = players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")

local gunC = RS.Tools.Gun:Clone()
gunC.Parent = plr:WaitForChild("Backpack")

Shouldn’t this be replicating the gun into the players backpack? When I press play nothing happens, and there’s no errors.
I even tried adding a print to the end and it still fires so I’m not sure
Probably really simple fix, any help would be much appreciated

1 Like

The script is executed before the character is added so it resets your backpack when you spawn, you can add a line to wait for the character to spawn.

local players = game:GetService("Players")
local plr = players.LocalPlayer
plr.CharacterAdded:Wait()
local RS = game:GetService("ReplicatedStorage")

local gunC = RS.Tools.Gun:Clone()
gunC.Parent = plr:WaitForChild("Backpack")
1 Like

Make a function to replicate the gun when the player joins the game.

local plr = players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:Connect(function()
local gunC = RS.Tools.Gun:Clone()
gunC.Parent = plr.Backpack
print(plr.Name.." has received the gun!") --  to ensure they got the gun
end)