So I am making a shop script and I ran into a problem when a player joins for the first time and has nothing in Backpack this script should run and adds started tools into their backpack. Instead, the script does not run.
Script:
game.Players.PlayerAdded:Connect(function(player) if #(player:FindFirstChild("Backpack"):GetChildren()) == 0 or nil then local x = game.ServerStorage.Loadout.Primary:Clone() x.Parent = player:FindFirstChild("Backpack") x.Name = "Primary" local y = game.ServerStorage.Loadout.Secondary["GLOCK 17"]:Clone() y.Parent = player:FindFirstChild("Backpack") y.Name = "Secondary" end end)
This should work
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function() if #(player:FindFirstChild("Backpack"):GetChildren()) == 0 or nil then local x = game.ServerStorage.Loadout.Primary:Clone() x.Parent = player:FindFirstChild("Backpack") x.Name = "Primary" local y = game.ServerStorage.Loadout.Secondary["GLOCK 17"]:Clone() y.Parent = player:FindFirstChild("Backpack") y.Name = "Secondary" end end end)